WMI is a powerful technique to find out information about local or remote computers, and you may have used Get-WmiObject before to do so (if not, you may want to google for this cmdlet).
In PowerShell 3.0, a new cmdlet named Get-CimInstance was added that seems to do exactly what Get-WmiObject does. But that is not true. While Get-WmiObject always uses DCOM to access remote systems, Get-CimInstance can use both DCOM and the new PowerShell remoting techniques. Even more important, with Get-CimInstance you can use persistent remoting sessions and reuse them across many calls. This can speed up remote access considerably.
Here is a sample that retrieves processor information using the old and the new way. Just make sure you replace the name of the remote system with a system that is online, and make sure remoting permissions are set up appropriately to access the remote system:
#requires -Version 3 # classic approach, always uses DCOM Get-WmiObject -Class Win32_Processor -ComputerName SERVER1 # modern approach, you choose the protocol # and you can reuse sessions $option = New-CimSessionOption -Protocol Dcom $session = New-CimSession -SessionOption $option -ComputerName SERVER1 Get-CimInstance -ClassName Win32_Processor -CimSession $session Remove-CimSession -CimSession $session
ReTweet this Tip!
Posted Feb 24 2016, 06:00 AM by ps1