Hi Have the below code where I am trying to get a total count of CPU cores on numerous servers.
What it returns for $result is 2 columns one for Cores which is blank/empty & one with computernames.
Trying to figure out what I did wrong & is causing the core count to be missing.
My ultimate goal is to get a total count of cores returned.
I will probably also do a export-csv of $result so I can capture it in a file.
Your variable $cores exits only within the scope of the script block, so your variable $cores in the hashtable doesn’t reference anything (or at least it doesn’t reference the result of your Get-WMIObject query).
Get-WMIObject is superseded by Get-CIMInstance. Consider something like this:
With my code suggestion you’re not running the commands on the remote computers!! If I’m not wrong it does not matter if they have PwSh at all. But it would take you only seconds to figure that out!
You don’t need a loop. Neither with Get-WmiObject nor with Get-CimInstance!! Both cmdlets can handle multiple remote computers at once.
If you’ve collected the core count of all servers you can use