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 🙂

Notify of

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

1 Comment
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Chris Ryder
Chris Ryder
6 months ago

Hi, I know this is old but this REALLY helped with our move from SCCM to Intune for Windows management. I have to run a PS1 file packaged in a Windows 32 IntuneWinApp. This PS1 calls other files in the package – so I couldn’t run it as a simple Intune Script (aware of the 32/64bit rocker switch).] Some cmdlets in use in my powershell script were 64bit based only. I was pulling my hair out why some functions were not running. It was only when I tested my local (x86) version of powershell that the light bulb went on.… Read more »