- PowerShell 2.0 Home
- PowerShell 2.0 Tutorial - Part I
- PowerShell 2.0 Tutorial - Part II
- PowerShell 2.0 Tutorial - Part III
- PowerShell 2.0 Tutorial - Part IV
- PowerShell 2.0 Tutorial - Part V
- PowerShell 2.0 Tutorial - Part VI
- Powershell 2.0 Tutorial - Part VII
- Powershell 2.0 Tutorial - Part VIII
- PowerShell 2.0 Tutorial - Part IX
PowerShell 2.0 Tutorial - Part VIII - Working with WMI Objects and Queries
Windows Management Instrumentation (WMI) provides a standardized interface for interacting with a Windows-based system regardless of the underlying hardware manufacturer and specific Windows version. WMI is a management framework that you can use to query a computer to determine its attributes. Computers running Windows XP and later versions of Windows support Windows Management Instrumentation (WMI). Working with WMI using Windows PowerShell is not that hard. In Windows PowerShell, you can use the Get-WMIObject cmdlet to get a WMI object that you want to work with. The basic syntax is
Get-wmiobject WMIclass
WMIclass = WMI class you want to work with.
for example:
Get-wmiobject win32_logicaldisk
Get-wmiobject win32_Bios
The default namespace in Windows is root\CIMV2. In general, you’re not going to want to change this unless you have a very specific reason because all the WIN32_ classes fall into this namespace. The Get-WMIObject command you issued earlier all work because it just so happens that the WMI classes you queried all belong to root\CIMV2. If you want to query a class outside of this namespace, you need to explicitly define it using the -namespace parameter. The basic Syntax is
Get-WmiObject -Class WMIClass -Namespace NameSpace –ComputerName
where
WMIClass is the WMI class you want to work with
NameSpace sets the namespace to use within WMI
ComputerName sets the name of the computer to work with
For Example:Get-WMIObject –class IISWebService -namespace “root\MicrosoftIISV2”
Using Get-WMIObject will give you information about all the instances of that class along with any properties it has. To find out information about your BIOS, you can run this line:Get-WMIObject Win32_BIOS
An easy way to see all the classes available is by using Get-WMIObject to list them out for you. Simply enter this:Get-WMIObject –list
You can use WMI queries to examine settings based on just about any measurable characteristic of a computer, including
- Amount of memory installed
- Available hard disk space
- Processor type or speed
- Network adapter type or speed
- Operating system version, service pack level, or hot fix
- System services that are running
- Registry key or key value
You create WMI queries using the WMI Query Language. The basic syntax is
Select * from WMIObjectClass where Condition
In above syntax, WMIObjectClass is the WMI object class you want to work with, and Condition is the condition you want to evaluate. The Select statement returns objects of the specified class. A condition has three parts:
- The name of the object property you are examining
- An operator, such as = for equals, > for greater than, or < for less than
- The value to evaluate
For example:
Get-WmiObject Win32_Service | Where-Object {($_.StartMode -eq “Auto”) -and ($_.State -ne “Running”)} | Select-Object DisplayName,Name,State
Get-WmiObject -query “Select * from Win32_Process where name=’notepad.exe’”
Some of the more commonly used WMI classes are as follows
|
WMI Class |
Short Description |
|
Win32_BIOS |
Properties related to System firmware. |
|
Win32_Processor |
A CPU on the system. |
|
Win32_Process |
Process running on the System. |
|
Win32_LogicalDisk |
Logical disk used in a machine. |
|
Win32_ComputerSystem |
Various properties of a computer running windows O/S. |
|
Win32_BaseBoard |
Motherboard info. |
|
Win32_BootConfiguration |
Represents computer boot configuration |
|
Win32_Directory |
Directory / Folder in Windows |
|
Win32_Environment |
Represents a system environment setting on a computer |
|
Win32_LogonSession |
Provides information about the current logon session |
|
Win32_NetworkAdapter |
Represents each network adapter on the computer |
|
Win32_NetworkAdapterConfiguration |
Represents the configuration of each network adapter on the computer |
|
Win32_Desktop |
Common configuration of user desktop |
|
Win32_PageFileUsage |
Represents the page file used for handling virtual memory swapping |
|
Win32_TimeZone |
System time zone |
|
Win32_Registry |
Windows Registry |
|
Win32_PhysicalMemoryArray |
Represents the total memory configuration of the computer by capacity and number of memory devices |
|
Win32_Share |
A shared resource on the system |
|
Win32_CacheMemory |
Represents cache memory on the computer |
|
Win32_DesktopMonitor |
Represents the type of monitor or display device connected to the computer |
|
Win32_DiskPartition |
Represents each partitioned area of a physical disk |
|
Win32_Printer |
Represents each configured print device on the computer |
|
Win32_PrinterConfiguration |
Represents configuration details for print devices |
|
Win32_ScheduledJob |
A task scheduled on the system |
|
Win32_QuickFixEngineeering |
Represents updates that have been applied to the computer |
|
Win32_Service |
Represents each service configured on the computer |
- 13/01/2011 00:52 - PowerShell 2.0 Tutorial - Part VII - Ten Most Important PowerShell Cmdlets
- 12/11/2010 02:17 - PowerShell 2.0 Tutorial - Part VI - Commonly Used Cmdlets for Administrator
- 07/10/2010 01:31 - PowerShell 2.0 Tutorial - Part V - Common Verbs Used with Cmdlets
- 01/10/2010 06:08 - PowerShell 2.0 Tutorial - Part IV - What's New In PowerShell 2.0 ?
- 17/09/2010 03:57 - PowerShell 2.0 Tutorial - Part III - Running PowerShell Script
- 17/09/2010 01:23 - PowerShell 2.0 Tutorial - Part II - Finding way around with Windows PowerShell
- 16/09/2010 11:53 - PowerShell 2.0 Tutorial - Part I - PowerShell Definition
Last Updated (Thursday, 03 February 2011 02:16)
Back







