none
How to detect is the PS host 32 or 64-bit? RRS feed

  • Question

  • Is there an easy way to tell in a PS script (or REPL mode) what is the concrete architecture of the host process (x86, x64, ARM)?   The get-host command unfortunately won't give a clue.

    -- pa

    Sunday, April 19, 2015 11:57 PM

Answers

  • Depends on what version of PowerShell you're running.  You can check [Environment]::Is64BitProcess (which I believe requires .NET 4.0 or later, so wouldn't work in PowerShell 2.0.)

    For PS 2.0 compatibility, generally people just check [IntPtr]::Size.  This will be 4 in a 32-bit process, and 8 in a 64-bit process.

    • Marked as answer by Pavel A Monday, April 20, 2015 1:51 AM
    Monday, April 20, 2015 1:17 AM

All replies

  • What's provoking the question?

    -- Bill Stewart [Bill_Stewart]

    Monday, April 20, 2015 12:46 AM
    Moderator
  • Depends on what version of PowerShell you're running.  You can check [Environment]::Is64BitProcess (which I believe requires .NET 4.0 or later, so wouldn't work in PowerShell 2.0.)

    For PS 2.0 compatibility, generally people just check [IntPtr]::Size.  This will be 4 in a 32-bit process, and 8 in a 64-bit process.

    • Marked as answer by Pavel A Monday, April 20, 2015 1:51 AM
    Monday, April 20, 2015 1:17 AM
  • What's provoking the question?

    -- Bill Stewart [Bill_Stewart]

    I need to call a native DLL that has versions per platform (at least, x86 and x64). Need to determine in runtime which one to call.  Even on a 64-bit OS the script can be run by 32-bit PS.

    -- pa


    • Edited by Pavel A Monday, April 20, 2015 2:10 AM
    Monday, April 20, 2015 1:55 AM