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

标签 powershell

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

get-wmiobject Win32_ComputerSystem

是否有任何命令可以获取物理 CPU 的数量?

最佳答案

从 PowerShell 3.0 开始, Get-WmiObject 已被 Get-CimInstance 取代.
物理 CPU 的数量(又名插槽)

@(Get-CimInstance -ClassName Win32_Processor).Count
或者:
(Get-CimInstance -ClassName Win32_ComputerSystem).NumberOfProcessors
物理核心数
(Get-CimInstance -ClassName Win32_Processor | Measure-Object -Property NumberOfCores -Sum).Sum
逻辑核心数
(Get-CimInstance -ClassName Win32_Processor | Measure-Object -Property NumberOfLogicalProcessors -Sum).Sum
或者:
(Get-CimInstance -ClassName Win32_ComputerSystem).NumberOfLogicalProcessors

关于用于获取物理 CPU 数量的 Powershell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47880162/

相关文章:

powershell - 如何使用带有证书身份验证的 powershell 获取 Azure Key Vault secret ?

Powershell 多个 StartsWith 子句

powershell - 将空值传递给 cmdlet 参数

powershell - 在PowerShell中使用.NET集合(ArrayList,List等)的小技巧

powershell - 如何从使用带有 ffmpeg 的时间戳命名的帧创建视频

powershell - 在PowerShell中解析 'query user'的更简单方法

powershell - 在 powershell 脚本中使用 "starts with"而不是包含?

Powershell 调用-SSHCommand : Exception calling “EndExecute” with “1” argument(s)

powershell - 解析大型文本文件最终导致内存和性能问题

powershell - Powershell环境变量继承