3

I am trying to find the total number of CPUs on a computer via get-wmiobject. The query: select * from win32_processor returns more than 1 row if there is more than 1 processor on the computer. WQL doesn't have the count keyword like in TSQL. So I am just wondering whether there is another way to find the total number of rows returned?

deutschZuid
  • 1,028
  • 2
  • 15
  • 33

2 Answers2

8

You can just force it into an array and use the Count property:

@(gwmi win32_processor).count

For the specific case, if you are just looking for number of processors, you can do:

$env:NUMBER_OF_PROCESSORS
manojlds
  • 290,304
  • 63
  • 469
  • 417
  • I do need the other bits of information from win32_processor as well, but thanks for the second suggestion! – deutschZuid Nov 30 '11 at 23:09
  • 3
    `@(gwmi win32_processor).count`will return the number of physical processors. `$env:NUMBER_OF_PROCESSORS` will return the number of logical processors. – jon Z Dec 01 '11 at 15:14
4

You can also try the Win32_OperatingSystem class:

Get-WmiObject -Class Win32_OperatingSystem -ComputerName localhost | `
   Select-Object NumberOfProcessors,NumberOfLogicalProcessors
Shay Levy
  • 121,444
  • 32
  • 184
  • 206