Reputation: 838
So my aim is to get the number of cores on the machine my powershell script runs on and work with it as an integer. Some googleing lead me to this nice and simple command to get the number of cores:
Get-WmiObject -Class Win32_ComputerSystem | fl NumberOfLogicalProcessors
Which displays an output like this:
NumberOfLogicalProcessors : 4
Now my issue is, how so I extract the number "4" from this? I tried .Split(":") but the output is not a string so that doesn't work. Next I tried
PS C:\Windows\system32> Get-WmiObject -Class Win32_ComputerSystem | fl NumberOfLogicalProcessors | select NumberOfLogicalProcessors
But this just yields:
"NumberOfLogicalProcessors
--------------------------------------"
Not helpful. What am I missing? What is this Get-WmiObject returning and how do I work with it?
Edit: Thank you mhu, that did the trick!
Upvotes: 0
Views: 2464
Reputation: 18061
Don't use Format-List
(fl), but directly select the required property, like this:
Get-WmiObject -Class Win32_ComputerSystem | select "NumberOfLogicalProcessors" -ExpandProperty "NumberOfLogicalProcessors"
As said by Mike, you could shorten this to:
Get-WmiObject -Class Win32_ComputerSystem | select -ExpandProperty "NumberOfLogicalProcessors"
Upvotes: 1