2

Does anybody know how to grab OS architecture remotely from multiple Windows hosts via PowerShell?

4 Answers 4

6

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

You'll pipeline the list of computer names into this command so that $_ is interpreted as each computer in your list.


Edit: After doing some digging, it appears that this will work on both 2003 and 2008.

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

4
  • Perfect, it works great. Is there a way to grab OS Architecture for 2003 servers the same way? Oct 15, 2012 at 13:48
  • Hm, I don't see anything in the win32_operatingsystem class properties on 2003 that would work. There might be something in win32_processor but I don't have anything handy to test it with.
    – MDMarra
    Oct 15, 2012 at 13:52
  • MDMarra, this is great! Thx for sharing this, that's really hepful. I've start digging into WMIC to get this info for Windows Server 2003 machines. Something like WMIC /NODE:"TESTSERVER1","TESTSERVER2",@"C:\COMPUTERLIST.TXT" cpu get DataWidth /format:list Oct 16, 2012 at 6:43
  • You know you can run that second PowerShell command against a 2003 machine remotely even if it doesn't have PowerShell installed, right? No need to mess with the voodoo black magic known as wmic :)
    – MDMarra
    Oct 16, 2012 at 10:58
2

For Windows XP/2003 and up, Win32_Processor has an AddressWidth property which will be 32 or 64, as appropriate.

There's 1 WMI object instance of class Win32_Processor for each CPU known to Windows' Device Manager, so I've typically done this sort of thing in the past. It's VBScript, my PowerShell sucks, but you get the idea...

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

update: translated to PowerShell:

If ($(Get-WmiObject -Query "SELECT * FROM Win32_Processor WHERE AddressWidth='64'")) {
    Write-Host "I'm x64"
} Else {
    Write-Host "I'm x86"
}
3
  • This is an interesting approach, but the OP asked for PowerShell.
    – MDMarra
    Oct 15, 2012 at 14:25
  • Fair enough, I figured that was simple enough to be translated to PowerShell by someone who is sufficiently familiar with it. I'm not. Oct 16, 2012 at 6:35
  • OK so...... killer Google-fu + a pocket full of common sense = PowerShell version. :-) Oct 16, 2012 at 6:49
0

Maybe a little less fancy, but for those who don't have remote WMI enabled, a little old-school way would be:

$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..."}
    }
}

Or something like that. The crux of the point being, test-path to Program Files (x86) which is only present on 64-bit machines.

-1

This works for me

PS > $env:processor_architecture
AMD64

PowerShell 32-bit or 64-bit

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .