Dav*_*ago 7 windows processor hyperthreading cpu-cores
这是困难的一个。
我需要使用命令从我的服务器输出确切数量的内核。
我的测试:
X:在具有 4 个处理器(插槽)和 2 个内核的 Windows 服务器上,每个内核都没有 HT。Y:在具有 2 个处理器(插槽)和 6 个内核的 Windows Server 上,每个内核都带有 HT。GetSystemInfo只为我提供安装的处理器数量:X 为 4,Y 为 2。
| | X: 8 cores | Y: 12 cores |
| | 4x2 (no HT) | 2x6 (HT) |
|----------------|-------------|-------------|
| Desired output | 8 | 12 |
| GetSystemInfo | 4 | 2 |
Run Code Online (Sandbox Code Playgroud)
%NUMBER_OF_PROCESSORS%是一个很好的,但它考虑到了HT。它告诉我 X 为 8,Y 为 24(因为它有 HT,我需要它显示 12)。
| | X: 8 cores | Y: 12 cores |
| | 4x2 (no HT) | 2x6 (HT) |
|------------------------|-------------|-------------|
| Desired output | 8 | 12 |
| GetSystemInfo | 4 | 2 |
| %NUMBER_OF_PROCESSORS% | 8 | 24 |
Run Code Online (Sandbox Code Playgroud)
"wmic cpu get NumberOfCores"获取每个套接字的信息。例如:
X:
>wmic cpu get NumberOfCores
NumberOfCores
2
2
2
2
Run Code Online (Sandbox Code Playgroud)
是:
>wmic cpu get NumberOfCores
NumberOfCores
6
6
Run Code Online (Sandbox Code Playgroud)
意义
| | X: 8 cores | Y: 12 cores |
| | 4x2 (no HT) | 2x6 (HT) |
|----------------------------|-------------|-------------|
| Desired output | 8 | 12 |
| GetSystemInfo | 4 | 2 |
| %NUMBER_OF_PROCESSORS% | 8 | 24 |
| wmic cpu get NumberOfCores | 2,2,2,2 | 6,6 |
Run Code Online (Sandbox Code Playgroud)
叹。
我希望在 CMD 中保持简单,但我正在考虑启动一个 Powershell 脚本来完成所有这些数学运算和其他事情。
有什么想法吗?
小智 14
您可以使用Get-ComputerInfo并限定您想要的属性。
$processor = Get-ComputerInfo -Property CsProcessors\n$processor.CsProcessors\nRun Code Online (Sandbox Code Playgroud)\n那应该给你类似的东西
\nName : Intel(R) Core(TM) i7-6600U CPU @ 2.60GHz\nManufacturer : GenuineIntel\nDescription : Intel64 Family 6 Model 78 Stepping 3\nArchitecture : x64\nAddressWidth : 64\nDataWidth : 64\nMaxClockSpeed : 2808\nCurrentClockSpeed : 2607\nNumberOfCores : 2 <== that one\nNumberOfLogicalProcessors : 4 \n\xe2\x80\xa6\n\xe2\x80\xa6\nRun Code Online (Sandbox Code Playgroud)\nNumberOfCores然后,只需在结果中查找即可。
小智 11
建议的命令在具有超过 64 个逻辑内核的计算机上不起作用
(Get-CimInstance Win32_ComputerSystem).NumberOfLogicalProcessors
提供逻辑核心数(HT 核心)
如果我理解您对每台服务器的问题,您想要检索一个整数,即物理处理器(核心)的总数。根据超线程是否可用并启用,这可能是逻辑处理器数量的一半,但您特别希望排除这些。
Win32_ProcessorWMI 类的实例代表单个处理器套接字。该NumberOfCores属性指示该套接字提供的物理处理器的数量。Get-CimInstance我们可以使用cmdlet在 PowerShell 中查询:
Get-CimInstance -ClassName 'Win32_Processor' `
| Select-Object -Property 'DeviceID', 'Name', 'NumberOfCores'
Run Code Online (Sandbox Code Playgroud)
要添加NumberOfCores每个Win32_Processor实例的属性,我们可以使用Measure-Objectcmdlet:
Get-CimInstance -ClassName 'Win32_Processor' `
| Measure-Object -Property 'NumberOfCores' -Sum
Run Code Online (Sandbox Code Playgroud)
结果对象Sum将包含物理核心的总数以及Count套接字的总数。
请注意,在旧版本的 Windows/PowerShell 上,您可能需要将Get-WmiObjectcmdlet替换为Get-CimInstance. 另外,如果您确实想获取逻辑(超线程)处理器的数量,您可以将该NumberOfLogicalProcessors属性替换为NumberOfCores. 从 Windows 10/Server 2016 开始,也有一个NumberOfEnabledCore属性。
如果我理解正确的话,这个 vbscript 会给你两者。Powershell方法 - https://blogs.technet.microsoft.com/heyscriptingguy/2011/09/26/use-powershell-and-wmi-to-get-processor-information/
\n\nOn Error Resume Next\n\nConst wbemFlagReturnImmediately = &h10\nConst wbemFlagForwardOnly = &h20\n\nSet objWMIService = GetObject("winmgmts:\\\\.\\root\\CIMV2")\nSet colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Processor", "WQL",wbemFlagReturnImmediately + wbemFlagForwardOnly)\n\nFor Each objItem In colItems\n WScript.Echo "NumberOfCores: " & objItem.NumberOfCores\n WScript.Echo "NumberOfLogicalProcessors: " & objItem.NumberOfLogicalProcessors\nNext\nRun Code Online (Sandbox Code Playgroud)\n\n如果服务器包含多个物理处理器,Powershell 可能会提供更好的报告布局。
\n\nGet-WmiObject \xe2\x80\x93class Win32_processor | ft systemname,Name,DeviceID,NumberOfCores,NumberOfLogicalProcessors\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
33581 次 |
| 最近记录: |