WMI and CIM

CIM/WMI is most commonly used to query information or configuration on a device. Through a class that represents a configuration, process, user etc. In PowerShell there are multiple ways to access these classes and instances, but the most common ways are by using the Get-CimInstance (CIM) or Get-WmiObject (WMI) cmdlets.


Available List

There are many classes available in CIM and WMI which are separated into multiple namespaces. The most common (and default) namespace in Windows is root/cimv2. To find the right class, it can useful to list all or search

Get-WmiObject -List Get-CimClass

You can search for specific classes using wildcards. Ex: Find classes containing the word process.

Get-WmiObject -List -Class "*Process*" Get-CimClass -ClassName "*Process*"

The root namespace is simply called root. You can list classes in another namespace using the -NameSpace parameter.

Get-WmiObject -Class "__Namespace" -Namespace "root" Get-CimClass -Namespace "root/SecurityCenter2"

Win32_BIOS

The Win32_BIOS WMI class represents the attributes of the computer system's basic input/output services (BIOS) that are installed on a computer.

Get-WmiObject -Class Win32_BIOS Get-CimInstance -ClassName Win32_BIOS

Win32_ComputerSystem

The Win32_ComputerSystem class represents a computer system operating in a Windows environment.

Get-WmiObject -Class Win32_ComputerSystem Get-CimInstance -ClassName Win32_ComputerSystem

Win32_NetworkAdapterConfiguration

The Win32_NetworkAdapterConfiguration class represents the attributes and behaviors of a network adapter.

Get-WmiObject -Class Win32_NetworkAdapterConfiguration Get-CimInstance -ClassName Win32_NetworkAdapterConfiguration

win32_logicaldisk

The win32_logicaldisk class presents information about logicaldisks, size and free space available.

get-WmiObject win32_logicaldisk Get-CimInstance -ClassName win32_logicaldisk DeviceID : C: DriveType : 3 ProviderName : FreeSpace : 438228828160 Size : 498396557312 VolumeName : OS DeviceID : D: DriveType : 5 ProviderName : FreeSpace : Size : VolumeName :

Using a filter

You can apply a filter to only get specific instances of a CIM/WMI-class. Filters are written using WQL (default) or CQL (add -QueryDialect CQL). -Filter uses the WHERE-part of a full WQL/CQL-query.

Get-WmiObject -Class Win32_Process -Filter "Name = 'powershell.exe'" Get-CimInstance -ClassName Win32_Process -Filter "Name = 'powershell.exe'"

Using a WQL-query:

You can also use a WQL/CQL-query to query and filter instances.

Get-CimInstance -Query "SELECT * FROM Win32_Process WHERE Name = 'powershell.exe'"

Use Remote WMI

The Get-WmiObject cmdlet may be used to connect to remote computers using the -ComputerName parameter, with a specified Credential if necessary.[

Get-WmiObject -Class Win32_BIOS -ComputerName 'RemoteHost' Get-CimInstance -ComputerName dc01 -ClassName Win32_BIOS Get-WmiObject -Class Win32_BIOS -ComputerName 'RemoteHost' -Credential 'RemoteHost\Username'
$CimSession = New-CimSession -ComputerName dc01 -Credential (Get-Credential) Get-CimInstance -CimSession $CimSession -ClassName Win32_BIOS