Skip to content

Instantly share code, notes, and snippets.

@davidvesely
Created July 17, 2019 00:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidvesely/d95c40c01769e8e2d4eea867e86fdaab to your computer and use it in GitHub Desktop.
Save davidvesely/d95c40c01769e8e2d4eea867e86fdaab to your computer and use it in GitHub Desktop.
Switching between PowerShell x86 and x64
# Put one of these blocks in front of your ps1 script
# Credits to http://vegetarianprogrammer.blogspot.com/2013/03/running-64-bit-powershell-from-32-bit.html
if ($env:PROCESSOR_ARCHITEW6432 -eq "AMD64") {
Write-Warning "Switching from 32bit to 64bit PowerShell"
$powershell = Join-Path $PSHOME.ToLower().Replace("syswow64","sysnative").Replace("system32","sysnative") powershell.exe
if ($myInvocation.Line) {
&"$powershell" -NonInteractive -NoProfile -ExecutionPolicy Bypass $myInvocation.Line
} else {
&"$powershell" -NonInteractive -NoProfile -ExecutionPolicy Bypass -file "$($myInvocation.InvocationName)" $args
}
exit $lastexitcode
}
if ($env:Processor_Architecture -ne "x86") {
Write-Warning "Switching from 64bit to 32bit PowerShell"
$powershell = Join-Path $PSHOME.ToLower().Replace("system32","syswow64") powershell.exe
if ($myInvocation.Line) {
&"$powershell" -NonInteractive -NoProfile -ExecutionPolicy Bypass $myInvocation.Line
} else {
&"$powershell" -NonInteractive -NoProfile -ExecutionPolicy Bypass -file "$($myInvocation.InvocationName)" $args
}
exit $LastExitCode
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment