PowerShell for Windows Admins

Apr 30 2013   12:32PM GMT

WMI vs CIM speed tests–the final round

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

As a final test I want to see what happened when I ran multiple commands against the remote machine.

PS> 1..100 | foreach { Measure-Command -Expression{1..100 | foreach { Get-WmiObject -Class Win32_ComputerSystem -ComputerName W12SUS;
Get-WmiObject -Class Win32_OperatingSystem -ComputerName W12SUS;
Get-WmiObject -Class Win32_LogicalDisk -ComputerName W12SUS}} } |
Measure-Object -Average TotalMilliseconds

Count    : 100 Average  : 6986.797156 Sum      : Maximum  :
Minimum  : Property : TotalMilliseconds

PS> 1..100 | foreach { Measure-Command -Expression{1..100 | foreach { Get-CimInstance -ClassName Win32_ComputerSystem -ComputerName W12SUS; Get-CimInstance -ClassName Win32_OperatingSystem -ComputerName W12SUS; Get-CimInstance -ClassName Win32_LogicalDisk -ComputerName W12SUS}} } | Measure-Object -Average TotalMilliseconds

Count    : 100 Average  : 8430.833188 Sum      : Maximum  :
Minimum  : Property : TotalMilliseconds

 

PS> $sess = New-CimSession -ComputerName W12SUS PS> 1..100 | foreach { Measure-Command -Expression{1..100 | foreach {
Get-CimInstance -ClassName Win32_ComputerSystem -CimSession $sess;
Get-CimInstance -ClassName Win32_OperatingSystem -CimSession $sess;
Get-CimInstance -ClassName Win32_LogicalDisk -CimSession $sess}} } |
Measure-Object -Average TotalMilliseconds

Count    : 100 Average  : 3460.203938 Sum      : Maximum  :
Minimum  : Property : TotalMilliseconds

WMI is slightly faster than CIM but using a CIM session is by far and away the fastest.

My conclusion is that WMI and CIM are comparable, with WMI having a slight edge for speed. If you want to run multiple commands against a remote machine you need to use a CIM session as it is way faster.

2  Comments on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • LaurelRaven
    So, I did a different version of this test, eliminating the foreach loop, which I think is slowing it down a lot.

    $adcomputers = Get-ADComputer -Filter * -SearchBase "ou=computers,dc=domain,dc=local" | select -ExpandProperty name
    $computers = Get-CimInstance Win32_OperatingSystem -ComputerName $adcomputers 2> $null | select -ExpandProperty CSName -first 100
    
    function Measure-WMISpeed {
        Measure-Command -Expression {Get-WmiObject Win32_OperatingSystem -ComputerName $computers} | select TotalMilliseconds
    }
    
    function Measure-CIMSpeed {
        Measure-Command -Expression {Get-CimInstance Win32_OperatingSystem -ComputerName $computers} | select TotalMilliseconds
    }

    Here are my results:

    PS C:\Windows\system32> $computers.Count
    100
    
    PS C:\Windows\system32> Measure-CIMSpeed
    
    TotalMilliseconds
    -----------------
    1322.2433
    
    
    
    PS C:\Windows\system32> Measure-WMISpeed
     
    
    TotalMilliseconds
    -----------------
    72450.404
    
    
    
    PS C:\Windows\system32> 

    I think the foreach loop is forcing it to wait for each query to finish before going on to the next one, while the cmdlets themselves are capable of connecting to multiple machines.
    10 pointsBadges:
    report
  • Richard Siddaway
    Thanks for the comment I was looking at the relative speeds not the absolute speeds
    4,355 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: