Get Operating System architecture(32-bit or 64-bit) using powershell
Updated on 2/13/2012 with a more robust function to get OS architecture and details.
After introduction of windows 7 and 2008, use of 64-bit operating systems have increased. Today I came across a requirement to generate list of servers which are running with 32-bit operating system and 64-bit operating system. I look at OperatingSystem attribute value of active directory objects, but that doesn’t have sufficient information. I did bit more research and came-up with below powershell script which works for windows XP, 2003, 7, 2008.
Code:
function Get-OSArchitecture { [cmdletbinding()] param( [parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)] [string[]]$ComputerName = $env:computername ) begin {} process { foreach ($Computer in $ComputerName) { if(Test-Connection -ComputerName $Computer -Count 1 -ea 0) { Write-Verbose "$Computer is online" $OS = (Get-WmiObject -computername $computer -class Win32_OperatingSystem ).Caption if ((Get-WmiObject -Class Win32_OperatingSystem -ComputerName $Computer -ea 0).OSArchitecture -eq '64-bit') { $architecture = "64-Bit" } else { $architecture = "32-Bit" } $OutputObj = New-Object -Type PSObject $OutputObj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $Computer.ToUpper() $OutputObj | Add-Member -MemberType NoteProperty -Name Architecture -Value $architecture $OutputObj | Add-Member -MemberType NoteProperty -Name OperatingSystem -Value $OS $OutputObj } } } end {} }
Usage:
Get-OSArchitecture -ComputerName PC1, PC2, PC3 | ft -auto
Hope this helps..
Hi,
On Windows Server 2003, the (get-wmiobject win32_operatingsystem).Caption command won’t give you any relevant information about the OS architecture. Unfortunately.
I tried it on a Server 2003 Std 32-bit and I got this: “Microsoft(R) Windows(R) Server 2003, Standard Edition”. I tried on Server 2003×64 as well and I got this: “Microsoft(R) Windows(R) Server 2003 Standard x64 Edition”. So I would not say that it is a right solution. Until now I didn’t find the right way how could I determine the architecture of my Server 2003.
On Server 2008Sp1 and R2 I use the (get-wmiobject win32_operatingsystem).OSArcitecture. It works properly. I recommend it.
@supi007, Whatever you said is correct. However, the code “(get-wmiobject win32_operatingsystem).Caption” returning is in fact having the version of Operating System. In case of 64-bit OS, you have in the returned value. In case of 32-bit, the returned value will not contain either 64 or 32-bit indication which means by default it is 32-bit. Only thing you need to do is, parse the code output and mark it as 64-bit if “x64″ is found in string, otherwise it is 32-bit.
Hope this explanation helps.
A simpler method is to look at the address width as follows:
$Processor = Get-WmiObject Win32_Processor -ComputerName SERVER -namespace rootcimv2 | where {$_.DeviceID -eq “CPU0″} | select AddressWidth
$Processor.AddressWidth will return 32 or 64, which will tell you what architecture it is. Limiting it to “CPU0″ makes sure you get just one 32 or 64 no matter how many processors there are. Works for Windows 2000 and up.
@Dave D -
The original example reports the OS architecture… Unless I misunderstand, you’re reporting the Processor architecture. They may not be the same, since you can run 32-bit Windows on 64-bit processors.
There are cases where you might want to know either piece of information, but they’re not necessarily the same thing.
Actually, I was wrong… looks like Dave D’s method will return the OS architecture correctly.
Back to lurking…
All of them are working properly. However, i would like to know if we can get the version of OS if it is R2. When i run this for Windows 2003 R2, it doesnt show up in the output.
Can some check this ?