July 5, 2018 at 5:07 am
We need to list #CORES per SQL Server Computer in our environment. (we have over 200 SQL Servers). This Powershell command works great for 1 computer:
Get-CimInstance -ClassName 'Win32_Processor' | Select-Object -Property 'DeviceID', 'Name', 'NumberOfCores';
Is there a way I can modify this to render the same output for MULTIPLE computer names? I don't necessarily need a FOREACH loop as I can just duplicate the above line 200 times w/ a FILTER on COMPUTER NAME.
I'm having difficulty incorporating the: -Filter "Name -like 'MyComputeName1*'" . Any help is greatly appreciated and thanks in advance.
July 5, 2018 at 6:43 am
RTFM is handy sometimes.
https://docs.microsoft.com/en-us/powershell/module/cimcmdlets/get-ciminstance?view=powershell-6
Get-CimInstance [-ComputerName <String[]>] ....
just build a string array with the names of the computers you need to query and pass it to the Get-CimInstance
On the output one of the properties will be populated with the computer name.
July 5, 2018 at 7:21 am
I embedded my original commandinto the -Invoke-Command ----- and specified the -ComputerName followed by the -ScriptBlock contents which was my original command.
Working Example:
Invoke-Command -ComputerName MyComputeName1 -ScriptBlock {Get-CimInstance -ClassName 'Win32_Processor' | Select-Object -Property 'NumberOfCores'; }
This worked nicely
July 5, 2018 at 8:04 am
Express12 - Thursday, July 5, 2018 7:21 AMI embedded my original commandinto the -Invoke-Command ----- and specified the -ComputerName followed by the -ScriptBlock contents which was my original command.Working Example:
Invoke-Command -ComputerName MyComputeName1 -ScriptBlock {Get-CimInstance -ClassName 'Win32_Processor' | Select-Object -Property 'NumberOfCores'; }
This worked nicely
You can specify computer name with just Get-CimInstance. With what you were originally trying to do, you could just add that parameter:
Get-CimInstance -ClassName Win32_Processor -ComputerName YourComputerName | select-object PSComputerName, Name, DeviceID, NumberOfCores
Sue
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy