locked
How do I get OS bitness using PowerShell Core RRS feed

  • Question

  • My script needs to determine if it's running under Windows IoT Core (32-bit) or under Windows Nano Server (64-bit).  

    For regular (non-Core) PowerShell scripts I'd just run '[System.Environment]::Is64BitOperatingSystem' to get the bitness of the OS.

    How do I do that under PowerShell Core?



    Monday, January 16, 2017 8:52 PM

Answers

  • Simple, if you just run PowerShell.exe then it start with the bitness of the OS. Check the PowerShell process itself.

    if ([System.IntPtr]::Size -eq 4) {
        '32-bit' 
    }
    else 
    {
        '64-bit' 
    }


    Cheers,

    Ruud
    Twitter:    Blog: AzureStack.Blog  LinkedIn:    
    Note: Please “Vote As Helpful” if you find my contribution useful or “Mark As Answer” if it does answer your question. That will encourage me - and others - to take time out to help you.


    Tuesday, January 17, 2017 9:53 AM

All replies

  • Why?

    -- Bill Stewart [Bill_Stewart]

    Tuesday, January 17, 2017 12:58 AM
  • Because I'm writing an install script for my product and I need to install the 32-bit components on IoT Core and the 64-bit ones on Nano Server.

    This'll work:

    if ($env:PROCESSOR_ARCHITECTURE.Contains("86") ) {$isWin64=$false}else{$isWin64=$true}

    But I'm not sure it's as robust as

    $isWin64=[System.Environment]::Is64BitOperatingSystem

    Tuesday, January 17, 2017 4:54 AM
  • Simple, if you just run PowerShell.exe then it start with the bitness of the OS. Check the PowerShell process itself.

    if ([System.IntPtr]::Size -eq 4) {
        '32-bit' 
    }
    else 
    {
        '64-bit' 
    }


    Cheers,

    Ruud
    Twitter:    Blog: AzureStack.Blog  LinkedIn:    
    Note: Please “Vote As Helpful” if you find my contribution useful or “Mark As Answer” if it does answer your question. That will encourage me - and others - to take time out to help you.


    Tuesday, January 17, 2017 9:53 AM
  • That works too.  Thanks
    Tuesday, January 17, 2017 7:05 PM