If you use a 64-bit OS it may not be clear which version of PowerShell you are using. 64-bit Windows will have both a 32-bit version and a 64-bit version of PowerShell installed. Having both versions installed may seem pointless, but it’s not.
Sometimes, while writing a script, it may be necessary to make sure you are using a specific version because a certain driver requires it. For instance, for a script I was writing I had to make sure I was using the 32-bit version of PowerShell because I needed to utilize the 32-bit Microsoft Access Database driver (don’t judge me, it wasn’t my fault). 64-bit PowerShell is not able to use it and therefore I was unable to create my database connection. :(
So how can you tell which version you’re running? Simple. All you have to do is run PowerShell from the locations below.
32-bit PowerShell | C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe |
64-bit PowerShell | C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe |
No, that’s not a typo! I’ve double-checked and double-checked this. That’s a quadruple check! The 64-bit version resides in the System32 folder and the 32-bit version is in the SysWOW64 folder. I’m assuming that Microsoft did this for backwards compatibility of folder locations. Again, just an assumption but lots of programs may call DLLs and EXEs from C:\Windows\System32 directly. To ensure things still work they kept the folder names the same. I would venture to guess that everything under SysWOW64 is 32-bit. Someone please correct me if I am wrong on this assumption.
Now, that may not be the answer you came here looking for. Perhaps what you were looking for is a way to tell IN CODE which version of PowerShell you are using. That too is pretty simple. We can do this by simply checking the SizeOf a System.IntPtr.
If the result of the above statement is 4, it is running in a 32-bit of PowerShell. If the result of the above statement is 8, it is running in a 64-bit of PowerShell.
The reason this works is because the size of System.IntPtr is platform specific. It will be 32 bits in 32-bit PowerShell and 64 bits in 64-bit PowerShell. If you wanted to throw this concept into a function, it would look something like below.
That’s not too bad! The above script is, of course, only returning a string but this could be easily modified into a Is32Bit() or Is64Bit() function!
Also, let me be clear on this that THIS WILL NOT TELL YOU THE ARCHITECTURE OF THE CPU! THIS WILL ONLY TELL YOU WHICH VERSION (32-BIT OR 64-BIT) OF POWERSHELL YOU ARE USING!