Home > PowerShell > Get Operating System architecture(32-bit or 64-bit) using powershell

Get Operating System architecture(32-bit or 64-bit) using powershell

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:

[powershell]
function Get-Architecture {
 param($computer) 
 (Get-WmiObject -computername $computer -class Win32_OperatingSystem ).Caption
 }
[/powershell]

Usage:

[PS]C:>Get-Architecture -computer server1

If your environment is having only windows 7 and windows 2008 servers, then you can use below onliner to determine the architecture version.

(Get-WmiObject Win32_OperatingSystem).OSArchitecture

Hope this helps..

No related content found.

  1. supi007
    April 19, 2011 at 3:16 pm | #1

    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.

  2. April 19, 2011 at 11:25 pm | #2

    @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.

  3. Dave D
    May 20, 2011 at 11:54 pm | #3

    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.

  4. Mark
    June 24, 2011 at 9:15 pm | #4

    @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.

  5. Mark
    June 24, 2011 at 9:24 pm | #5

    Actually, I was wrong… looks like Dave D’s method will return the OS architecture correctly.

    Back to lurking…

  6. Krishna
    November 23, 2011 at 8:09 pm | #6

    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 ?

  1. No trackbacks yet.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>