We are use to using Get-WmiObject to retrieve information from WMI. if you have been following this blog for any length of time you will have see lots of examples of that particular cmdlet. The CIM equivalent is Get-CIMInstance. It might appear that Get-CIMClass would be used but that is used to get information about the WMI class itself. think Get-WmiObject –List on steroids.
This should be familiar
Get-WmiObject -Class Win32_ComputerSystem
The direct comparison is
Get-CimInstance -ClassName Win32_ComputerSystem
We can run WQL queries
$q = "SELECT * FROM Win32_ComputerSystem"
Get-WmiObject -Query $q
Get-CimInstance -Query $q
And we can filter
Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType=3"
Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3"
Another difference is that CIM cmdlets tend to default to a table output but WMI cmdlets tend to default to a list
We can even select properties
Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType=3" -Property DeviceID, FreeSpace, Size
Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" -SelectProperties DeviceID, FreeSpace, Size
Here we get a big difference
WMI returns the properties we asked for plus the System properties (those starting with __) for the class. CIM returns the whole object but only the select properties and the system type properties are populated.
So far you could be forgiven for thinking these are very similar and we don’t need both. The big differences come when we look at accessing remote machines next time.