PowerShell function to determine if running on 64 bit machine

Easy a pie:

function is64bit() {
if ([IntPtr].Size -eq 4) { return $false }
else { return $true }
}

Explanation: the size of an IntPtr will be 4 bytes on a 32 bit machine and 8 bytes on a 64 bit machine.

I came across the tip somewhere (blog, usenet??) but I couldn't find it again - so I thought I'd share it here for anybody else who is looking for it.

Technorati Tags:

Print | posted on Friday, February 20, 2009 10:21 AM

Feedback

# re: PowerShell function to determine if running on 64 bit machine

Left by Martin at 2/20/2009 12:00 PM
Gravatar Here's a shorter variant:

function Is64Bit
{
[IntPtr]::Size -eq 8
}

# re: PowerShell function to determine if running on 64 bit machine

Left by Lance Robinson at 5/21/2009 5:11 PM
Gravatar Just to clarify - this will still return false if you're running in a 32 bit process on a 64 bit machine!

# re: PowerShell function to determine if running on 64 bit machine

Left by Vincent Hoogendoorn at 11/2/2009 10:20 PM
Gravatar Hi there, I wrote the OSArchitecture PowerShell function to always get the correct bit width of the OS, even when you are running in a 32 bits process on a 64 bits machine (i.e. under WoW64).

See http://vincenth.net/blog/archive/2009/11/02/detect-32-or-64-bits-windows-regardless-of-wow64-with-the-powershell-osarchitecture-function.aspx

Your comment:





 
 

Copyright © Lance Robinson

Design by Bartosz Brzezinski

Design by Phil Haack Based On A Design By Bartosz Brzezinski