0

I need to be able to launch the 64-bit version of PowerShell.exe I verify that I'm in the 64-bit version by checking the value of [system.intptr]::size is 8.

zumalifeguard
  • 8,648
  • 5
  • 43
  • 56

2 Answers2

5

To launch a 64-bit version of PowerShell:

  • From a 32-bit process, use path:

    c:\windows\sysnative\WindowsPowerShell\v1.0\powershell.exe
    
  • From a 64-bit process, use path:

    c:\windows\System32\WindowsPowerShell\v1.0\powershell.exe
    

If you make a mistake, and launch:

    c:\windows\System32\WindowsPowerShell\v1.0\powershell.exe

from a 32-bit process, you'll get the 32-bit version of PowerShell. And if you mistakenly launch:

    c:\windows\sysnative\WindowsPowerShell\v1.0\powershell.exe

from a 64-bit process, you'll get an error because from a 64-bit process the c:\windows\sysnative\ path is an error.

zumalifeguard
  • 8,648
  • 5
  • 43
  • 56
0

Another quick way of launching the executable corresponding to the OS Architecture:

# Get default executable path
$exePath = Join-Path $PSHome powershell.exe

# Test bitness
if([System.Environment]::Is64BitOperatingSystem -xor [System.Environment]::Is64BitProcess){
    # 32-bit process on 64-bit OS
    $exePath = $exePath -replace 'syswow64','sysnative'
}

# Launch new shell
& $exePath 'arguments go here'
Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206
  • Should not it be `-replace 'SysWOW64', 'sysnative'` instead of `-replace 'system32','sysnative'`? – user4003407 Apr 08 '17 at 16:34
  • This is good to know, but the question was not related to the OS architecture. The question applies only to 64-bit OS. Within a 64-bit OS, you can run a 64-bit process or a 32-bit process. How does such a process ensure they launch the 64-bit version of PowerShell. That's the question. – zumalifeguard Apr 13 '17 at 07:44