locked
Use Get-CimInstance to count processor sockets per server RRS feed

  • Question

  • I would like to get a report of processor information for multiple servers so that each server is on one line and not each server processor on its own line.  A column in the output would include the socket count instead.  I know how to do with a foreach loop - but it is super slow for many servers.  Using Get-CimInstance with an array of server names is much faster, but I cannot get my output correct.

    Here is what I am trying.  This works exactly the way I want for ONE server.  I only get one line of output and the Processors column shows the total number - whether it is just one processor or many.

    Get-CimInstance Win32_Processor -ComputerName "ServerName" -OutVariable CPU | Measure-Object |
    Select-Object @{N = "Server Name"; E = {$CPU[0].PSComputerName}},
    @{N = "Processor Model"; E = {$CPU[0].Name -replace "\s+"," "}},
    @{N = "Processors"; E = {$_.Count}},
    @{N = "Cores"; E = {$CPU[0].NumberOfCores}}

    But when I try this with an array of servers for the "ComputerName" parameter, it just shows the very last server in the list, and the Processors column shows the total processors of ALL servers in the list.

    So is there a trick to get this to count processors for each server in the list and display the results for ALL servers?

    Also, I am not too thrilled about hard-coding the first element in the array ($CPU[0]) to show the information correctly, but I am not sure how to get around that a better way either.

    Thanks

    NK



    • Edited by NJK-Work Wednesday, March 21, 2018 2:51 PM
    Wednesday, March 21, 2018 2:51 PM

Answers

  • Apply the very simple logic of PowerShell remoting here.

    execute what ever runs locally in a remote system using Invoke-Command

    Small variation of your code

    Invoke-Command $ServerList {
    Get-CimInstance Win32_Processor | Measure-Object |
     Select-Object @{N = "Server Name"; E = {$Env:ComputerName}},
     @{N = "Processor Model"; E = {$_.Name -replace "\s+"," "}},
     @{N = "Processors"; E = {$_.Count}},
     @{N = "Cores"; E = {$_.NumberOfCores}} 
    }


    Regards kvprasoon


    • Edited by PRASOON KARUNAN V Wednesday, March 21, 2018 7:22 PM
    • Marked as answer by NJK-Work Wednesday, March 21, 2018 7:36 PM
    Wednesday, March 21, 2018 7:21 PM

All replies

  • hi,

    i would Change your Code:

    $Servers = "List of Servers"
    
    foreach ($Server in $Servers) {
            $result += Get-CimInstance Win32_Processor -    ComputerName "ServerName" -OutVariable CPU | Measure-Object |
            Select-Object @{N = "Server Name"; E = {$CPU  [0].PSComputerName}},
            @{N = "Processor Model"; E = {$CPU[0].Name    
            -replace "\s+"," "}},
            @{N = "Processors"; E = {$_.Count}},
            @{N = "Cores"; E = {$CPU[0].NumberOfCores}} 
    }
    $result


    regards Thomas Paetzold visit my blog on: http://sus42.wordpress.com

    Wednesday, March 21, 2018 4:37 PM
  • Thank you for your response. I was hopefully to find a solution that did not use foreach, as that is really slow for many servers.

    NK

    Wednesday, March 21, 2018 5:07 PM
  • Apply the very simple logic of PowerShell remoting here.

    execute what ever runs locally in a remote system using Invoke-Command

    Small variation of your code

    Invoke-Command $ServerList {
    Get-CimInstance Win32_Processor | Measure-Object |
     Select-Object @{N = "Server Name"; E = {$Env:ComputerName}},
     @{N = "Processor Model"; E = {$_.Name -replace "\s+"," "}},
     @{N = "Processors"; E = {$_.Count}},
     @{N = "Cores"; E = {$_.NumberOfCores}} 
    }


    Regards kvprasoon


    • Edited by PRASOON KARUNAN V Wednesday, March 21, 2018 7:22 PM
    • Marked as answer by NJK-Work Wednesday, March 21, 2018 7:36 PM
    Wednesday, March 21, 2018 7:21 PM
  • Thanks. That got me pretty much where I needed to be. I still had to use the Outvariable though otherwise cores and processor model returned blank results.

    $ScriptBlock = {Get-CimInstance Win32_Processor -OutVariable CPU | Measure-Object |
    Select-Object @{N = "Server Name"; E = {$Env:ComputerName}},
    @{N = "Processor Model"; E = {$CPU[0].Name -replace "\s+"," "}},
    @{N = "Processors"; E = {$_.Count}},
    @{N = "Cores"; E = {$CPU[0].NumberOfCores}}}

    $Results = Invoke-Command -ComputerName $MyServers -ScriptBlock $ScriptBlock

    Wednesday, March 21, 2018 7:36 PM