Skip to content

Instantly share code, notes, and snippets.

@talatham
Created October 27, 2016 10:31
Show Gist options
  • Save talatham/ad406d5428ccec641f075a7019cd29a8 to your computer and use it in GitHub Desktop.
Save talatham/ad406d5428ccec641f075a7019cd29a8 to your computer and use it in GitHub Desktop.
Force Powershell to run as x64-bit if required.
if (($pshome -like "*syswow64*") -and ((Get-WmiObject Win32_OperatingSystem).OSArchitecture -like "64*")) {
write-warning "Restarting script under 64 bit powershell"
# relaunch this script under 64 bit shell
& (join-path ($pshome -replace "syswow64", "sysnative")\powershell.exe) -file $myinvocation.mycommand.Definition @args
# This will exit the original powershell process. This will only be done in case of an x86 process on a x64 OS.
exit
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment