Using CIM to get data from computers running PowerShell 2

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.
For example:

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 *

or
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.

CIM doesn’t exist in v2. You can use the CIM cmdlets on your computer but you have to set a session option so they connect by DCOM instead of WSMAN. In other words, the CIM commands can connect to the old WMI service - but they’re limited to its capabilities.

I have a blog article that I wrote a while back about targeting down level clients with the Get-CIMInstance cmdlet that you might find interesting. You actually don’t even need PowerShell installed at all on the remote computers if you create a CIM session option for DCOM on your workstation that has at least PowerShell version 3 installed and target the remote computers using that option. I used this during the scripting games last year to target servers running Windows 2000 and here’s a blog about that.