Created
July 17, 2019 00:22
-
-
Save davidvesely/d95c40c01769e8e2d4eea867e86fdaab to your computer and use it in GitHub Desktop.
Switching between PowerShell x86 and x64
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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