Scripting

Determining if your system is a 32bit or 64bit system via PowerShell

During my spare time here in Honduras, I am doing some freelance work for companies via various sites on the web. One of these tasks asked me to build a PowerShell script to perform some basic tasks, however there has been 1 snag – 32bit or 64bit OS?
I need to determine the OS version to execute the right commands, at first this is an easy thing to find, look in the Win32_OperatingSystem for the OSArchitecture attribute. If it’s 32bit, then the OS is 32bit, otherwise it’s 64bit.

However, a problem comes up with Windows XP systems – they don’t have this value in WMI. When I wrote the script initially, I assumed that XP systems were out of scope due to their age (probably silly). So out to the internet I go and I find tons of methods to determine if the OS version is 32 or 64bit.
The most complete posting I have found was at http://depsharee.blogspot.com/2011/06/how-do-detect-operating-system.html, and it seems to suggest that the Win32_Processor.AddressWidth is the ideal WMI key to use. This works in Windows XP through 2012, so it should cover all of my needs.

Another option that isn’t listed is to use the Test-Path PowerShell command. 64bit Operating Systems create a folder named C:Program Files (x86) to separate 32 and 64 bit applications. We could then check for this path to see if the OS is running 64bit. This probably isn’t the most reliable method as the OS could be installed on something other than the C: drive and with different default locations, but if you are only looking for a file to execute, it may be a shortcut.

Leave a Reply