Restarting a x86 Powershell Process as x64 automatically

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)){
if([Environment]::Is64BitOperatingSystem){
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"
Exit
}else{
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 🙂