Quick one – inspired by today’s Power Tip on Powershell.com, I ran a comparison of different methods of getting data from WMI on a remote computer and the execution time of each. The results were interesting, with Get-CimInstance the clear winner.
I retrieved the full property list for the Win32_Processor class from a remote computer with a ~290ms latency.
$ComputerName = "remoteserver-01" ## 4.54 Seconds # Get-CimInstance [math]::Round($(Measure-Command -Expression {Get-CimInstance -ClassName Win32_Processor -ComputerName $ComputerName -Property *} | Select -ExpandProperty TotalSeconds),2) ## 4.59 Seconds # Get-CimInstance in WSMan Session [math]::Round($(Measure-Command -Expression { $option = New-CimSessionOption -Protocol Wsman $session = New-CimSession -SessionOption $option -ComputerName $ComputerName Get-CimInstance -ClassName Win32_Processor -CimSession $session -Property * Remove-CimSession -CimSession $session }| Select -ExpandProperty TotalSeconds),2) ## 7.68 Seconds # Invoke-Command / Get-CimInstance [math]::Round($(Measure-Command -Expression {invoke-command -ComputerName $ComputerName -scriptblock {Get-CimInstance -ClassName Win32_Processor -Property *}} | Select -ExpandProperty TotalSeconds),2) ## 8.37 Seconds # Invoke-Command / Get-WMIObject [math]::Round($(Measure-Command -Expression {invoke-command -ComputerName $ComputerName -scriptblock {Get-WmiObject -Class Win32_Processor -Property *}} | Select -ExpandProperty TotalSeconds),2) ## 11.04 Seconds # Get-CimInstance in Dcom session [math]::Round($(Measure-Command -Expression { $option = New-CimSessionOption -Protocol Dcom $session = New-CimSession -SessionOption $option -ComputerName $ComputerName Get-CimInstance -ClassName Win32_Processor -CimSession $session -Property * Remove-CimSession -CimSession $session }| Select -ExpandProperty TotalSeconds),2) ## 15.31 Seconds # Get-WmiObject [math]::Round($(Measure-Command -Expression {Get-WmiObject -Class Win32_Processor -ComputerName $ComputerName -Property *} | Select -ExpandProperty TotalSeconds),2)