Restarting a x86 Powershell Process as x64 automatically

2/27/2019 update: intune now supports starting your scripts as 64 bit!

Let’s say something (like Intune) starts your Powershell script in 32 bit and you really need commands that only 64 bit Powershell has….

#Restart self in x64
If (!([Environment]::Is64BitProcess)){
        Write-Output "Running 32 bit Powershell on 64 bit OS, restarting as 64 bit process..."
        $arguments = "-NoProfile -ExecutionPolicy ByPass -WindowStyle Hidden -File `"" + $myinvocation.mycommand.definition + "`""
        $path = (Join-Path $Env:SystemRoot -ChildPath "\sysnative\WindowsPowerShell\v1.0\powershell.exe")
        Start-Process $path -ArgumentList $arguments -wait
        Write-Output "finished x64 version of PS"
        Write-Output "Running 32 bit Powershell on 32 bit OS"

With the above at the top of your script, it’ll automatically restart itself if needed 🙂

Leave a Reply


This site uses Akismet to reduce spam. Learn how your comment data is processed.

Notify of