I recently started using the CIM cmdlets available in PS3+ and they’re spectacularly faster than the previous combination of Invoke-Command and Get-WMIObject calls I had been using. However, everything I was reading said that CMI cmdlets couldn’t be used to query computers running PS2. I wanted to write up something so people know this isn’t completely true.
Yes, if you attempt to retrieve an instance of a class, you will get an error.
Get-CimInstance -ComputerName c2phb100 -ClassName Win32_OperatingSystem
will error with this:
Get-CimInstance : The WS-Management service cannot process the request. A DMTF resource URI was used to access a non-DMTF
class. Try again using a non-DMTF resource URI.
At line:1 char:1
- Get-CimInstance -ComputerName c2phb100 -ClassName Win32_OperatingSystem
+ CategoryInfo : NotSpecified: (root\cimv2:Win32_OperatingSystem:String) [Get-CimInstance], CimException + FullyQualifiedErrorId : HRESULT 0x80338139,Microsoft.Management.Infrastructure.CimCmdlets.GetCimInstanceCommand + PSComputerName : c2phb100
However, if you include either the Property parameter or a Query value, such as:
Get-CimInstance -ComputerName c2phb100 -ClassName Win32_OperatingSystem -Property *
Get-CimInstance -ComputerName c2phb100 -Query “SELECT * from Win32_OperatingSystem”
The CIMInstance object is returned without error.
I’m sure people much smarter than I can give a detailed explanation of why this works. My goal with this post is to help inform those still using PS2 in much of their environment that they can still query these servers via CIM from a server running PS3 or later.