PLEASE READ FIRST!

I've now been blogging here since 2007! ...Wow, has it been that long already?! Over the years, I've covered a wide array of subjects from scripting, troubleshooting, to the occasional hobby project. I have literally heard from thousands of you over the years with questions or even just offering me a bit of thanks!

Recently, I quit my full-time job and started work on an IT business, Rhythm IT Solutions, helping other IT departments manage their IT environments. We're offering consulting & professional services (Office 365 Migrations, Network Discovery, Firewall Management, etc...) as well as Endpoint Management (AV, Patch Management EDR, Managed Backup, etc...)



If there is something (on my blog or not) that you could use some additional help with, I would LOVE to hear from you! Please feel free to reach out to me using the contact links here or the contact form on Rhythm's website.

For those wondering, I do plan on continuing my work on the blog. So don't worry! There are plenty of Greg Strike posts yet to come! 😊 Thanks for stopping by!

PLEASE READ FIRST!




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.

[System.Runtime.InterOpServices.Marshal]::SizeOf([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.

#  Script name:     Get-Bits.ps1
#  Created on:      2011-01-27
#  Author:          Gregory Strike
#  Website:         www.gregorystrike.com
#
#  Purpose:         Outputs which version (32-bit or 64-bit) of PowerShell is currently being run.
#
#  Requirements:    There are no special requirements.

Function Get-Bits(){
    Switch ([System.Runtime.InterOpServices.Marshal]::SizeOf([System.IntPtr])) {
        4 {
            Return "32-bit"
        }

        8 {
            Return "64-bit"
        }

        default {
            Return "Unknown Type"
        }
    }
}

Get-Bits

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!



PLEASE READ FIRST!

I've now been blogging here since 2007! ...Wow, has it been that long already?! Over the years, I've covered a wide array of subjects from scripting, troubleshooting, to the occasional hobby project. I have literally heard from thousands of you over the years with questions or even just offering me a bit of thanks!

Recently, I quit my full-time job and started work on an IT business, Rhythm IT Solutions, helping other IT departments manage their IT environments. We're offering consulting & professional services (Office 365 Migrations, Network Discovery, Firewall Management, etc...) as well as Endpoint Management (AV, Patch Management EDR, Managed Backup, etc...)



If there is something (on my blog or not) that you could use some additional help with, I would LOVE to hear from you! Please feel free to reach out to me using the contact links here or the contact form on Rhythm's website.

For those wondering, I do plan on continuing my work on the blog. So don't worry! There are plenty of Greg Strike posts yet to come! 😊 Thanks for stopping by!

PLEASE READ FIRST!





Gregory Strike

Husband, father, IT dude & blogger wrapped up into one good looking package.