用于获取物理 CPU 数量的 Powershell 脚本

Pra*_*hag 3 powershell

我尝试使用下面的脚本获取物理 CPU 的数量,但无法获得所需的结果。

get-wmiobject Win32_ComputerSystem
Run Code Online (Sandbox Code Playgroud)

有没有命令可以获取物理CPU的数量

sta*_*tor 5

从 PowerShell 3.0 开始,Get-WmiObject已被Get-CimInstance.

物理 CPU(又称插槽)数量

@(Get-CimInstance -ClassName Win32_Processor).Count
Run Code Online (Sandbox Code Playgroud)

或者:

(Get-CimInstance -ClassName Win32_ComputerSystem).NumberOfProcessors
Run Code Online (Sandbox Code Playgroud)

物理核心数量

(Get-CimInstance -ClassName Win32_Processor | Measure-Object -Property NumberOfCores -Sum).Sum
Run Code Online (Sandbox Code Playgroud)

逻辑核心数

(Get-CimInstance -ClassName Win32_Processor | Measure-Object -Property NumberOfLogicalProcessors -Sum).Sum
Run Code Online (Sandbox Code Playgroud)

或者:

(Get-CimInstance -ClassName Win32_ComputerSystem).NumberOfLogicalProcessors
Run Code Online (Sandbox Code Playgroud)