PowerShell CIM Session in PowerShell Version 2.0
Requirement
Need to fetch OS installed date report on remote machine.
Explanations
Use Win32_OperatingSystem Class.
Use CIM_operating instance.
Scenario
Need CIM class because it looks fine. Don't need to format the date. The default output is fine. Few minutes later the phone rang and it's failing in V2. Could you please explain?
Points and Explanation
CIM was introduced in PowerShell Version 3.0. It's obvious it fails in V2. You can't use Invoke-Command. Error: The term 'Get-CimInstance' is not recognized as the name of a cmdlet, function, script file, or operable program.
Solution
How about using CIM Sessions? Yes, we are near by let's try using it.
Test-WSMan -ComputerName 'RemoteServer' wsmid : http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd ProtocolVersion : http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd ProductVendor : Microsoft Corporation ProductVersion : OS: 0.0.0 SP: 0.0 Stack: 2.0 |
Fine, now we know WSMAN stack says 2.0 - it's clear.
$dcom = New-CimSessionOption -Protocol Dcom #$dcom $Remote = New-CimSession -ComputerName 'RemoteServer' -SessionOption $dcom #$Remote (Get-CimInstance -CimSession $Remote -ClassName CIM_OperatingSystem).InstallDate |
We got the fix now. Enjoy PowerShell.