
PowerShell 経由で複数の Windows ホストから OS アーキテクチャをリモートで取得する方法を知っている人はいますか?
答え1
get-wmiobject win32_operatingsystem -computer $_ | select-object OSArchitecture
コンピューター名のリストをこのコマンドにパイプライン処理して、$_ がリスト内の各コンピューターとして解釈されるようにします。
編集: 調べてみたところ、これは 2003 と 2008 の両方で動作するようです。
get-wmiobject win32_computersystem -computer $_ | select-object systemtype
答え2
Windows XP/2003 以降の場合、Win32_Processor には AddressWidth プロパティがあり、その値は 32 または 64 のいずれか適切な値になります。
Windows のデバイス マネージャーに認識される CPU ごとに、Win32_Processor クラスの WMI オブジェクト インスタンスが 1 つあるため、私はこれまでこの種のことをよく行ってきました。これは 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"
}
答え3
少し派手ではないかもしれませんが、リモート 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..."}
}
}
または、そのようなもの。要点は、64 ビット マシンにのみ存在する Program Files (x86) への test-path です。