This topic contains 2 replies, has 3 voices, and was last updated by
May 5, 2014 at 7:23 pm #15036ParticipantPoints: 1Rank: Member
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.
May 6, 2014 at 5:29 am #15053KeymasterPoints: 1,785Rank: Community Hero
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.
May 6, 2014 at 5:45 am #15054ParticipantPoints: 53Rank: Member
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.
The topic ‘Using CIM to get data from computers running PowerShell 2’ is closed to new replies.