Occasionally it might be interesting to know whether your current PowerShell session is running in 64-bit. This tip describes how to determine this and how to start either a 32 or 64-bit session of PowerShell. To quickly determine if you current PowerShell session is 32 or 64-bit use the following code:
[System.IntPtr]::Size |
There are two possible results from this code:
- 4 – x86
- 8 – x64
Keep this in mind, especially if you intend to execute memory dependent tasks in Powershell, the testing if the script is executing in a 64 bit context is a good idea.
If a system is 64-bit the following two paths are available for the PowerShell executable:
- C:\WINDOWS\SysWOW64\WindowsPowerShell\v1.0\powershell.exe (32-bit)
- C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe (64-bit)
Also, you can use this in PS3+ I believe:[environment]::is64bitProcess
Indeed, and if you’re interested Keith Hill wrote a nice blog post showing how c# can be used to determine if any process is either 32/64 bit:
http://rkeithhill.wordpress.com/2014/04/28/how-to-determine-if-a-process-is-32-or-64-bit/