通过PowerShell远程获取OS体系结构

有谁知道如何通过PowerShell从多个Windows主机远程获取OS体系结构?

get-wmiobject win32_operatingsystem -computer $_ | select-object OSArchitecture

您将把计算机名称列表传送到此命令中,以便将$ _解释为列表中的每台计算机。


编辑:经过一番挖掘,似乎这将在2003年和2008年工作。

get-wmiobject win32_computersystem -computer $_ | select-object systemtype

对于Windows XP / 2003或更高版本,Win32_Processor具有一个AddressWidth属性,根据需要将为32或64。

对于Windows设备pipe理器已知的每个CPU,有一个Win32_Processor类的WMI对象实例,所以我通常在过去做过这样的事情。 这是VBScript,我的PowerShell糟透了,但你明白了…

 Set objWMIService = GetObject("winmgmts:\\.\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor WHERE AddressWidth='64'") If colItems.Count = 0 Then strArch = "x86" Else strArch = "x64" End If 

更新 :翻译成PowerShell:

 If ($(Get-WmiObject -Query "SELECT * FROM Win32_Processor WHERE AddressWidth='64'")) { Write-Host "I'm x64" } Else { Write-Host "I'm x86" } 

这对我有用

 PS > $env:processor_architecture AMD64 

PowerShell 32位或64位

也许不那么花哨,但对于那些没有启用远程WMI的人来说,有点老派的方式是:

 $compList = #<whatever you use to source your list of machines> ForEach($comp in $compList){ $testPath64 = '\\' + $comp + '\c$\Program Files (x86)' $testPath = '\\' + $comp + '\c$\Program Files' $arch = Test-Path $testPath64 If($arch){Write-Host "$comp is x64"} Else{ $arch = Test-Path $testPath If($arch){Write-Host "$comp is x86"} Else{Write-Host "No idea..."} } } 

或类似的东西。 问题的症结在于,程序文件(x86)的testingpath仅存在于64位机器上。