PowerShell Script to get the number of CPU cores on server remotely

Hi,

We are trying to prepare an inventory of number of CPU cores assigned to servers. The idea is to have a report with server name and CPU cores columns. Below PowerShell has been tried but did not get the result. Anyone can support on this.

$ServerList = Get-Content “C:\ServerPatchReport\ServerListCPU.txt”|
ForEach ($Server in $ServerList){$CPU = (Get-CimInstance Win32_ComputerSystem).NumberOfLogicalProcessors ; Write-Host $Server,$CPU }

Could you please format your code as code here in the forum?

When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in PowerShell.org 1 <---- Click :point_up_2:t4: :wink:

( !! Sometimes the preformatted text button hides behind the settings gear symbol. :wink: )

You do not need a loop for that:

$ComputerNameList = 
    Get-Content -Path 'C:\ServerPatchReport\ServerListCPU.txt'
$CimSessionList = 
    New-CimSession -ComputerName $ComputerNameList
$ResultList = 
    Get-CimInstance -ClassName CIM_ComputerSystem -CimSession $CimSessionList
$ResultList | 
    Select-Object -Property Name, NumberOfLogicalProcessors 

Thanks a lot for the support.

Does that mean it works and your question is answered? :thinking:

Yes, it worked. Thanks again.

I’m glad to hear that. :+1:t3: You’re welcome. :slightly_smiling_face: :love_you_gesture:t3: