Forum Discussion
Below Powershell script is not working without running as administrator.
- Jun 27, 2024
Hi Rambo363636
I understand that pain. I assume that is an issue with the 32 and 64-bit versions.
Could you please put the script code below at the beginning of your script and try to push it again?
If ($ENV:PROCESSOR_ARCHITEW6432 -eq "AMD64") {
Try {
&"$ENV:WINDIR\SysNative\WindowsPowershell\v1.0\PowerShell.exe" -File $PSCOMMANDPATH
}
Catch {
Throw "Failed to start $PSCOMMANDPATH"
}
Exit
}
Please mark it as resolved if this is the solution for you.
Thank you.
Thihan
Hi, Thihan.
For your example, you'll need to swap the sysnative reference out and put in syswow64, as your example is assuming the calling process is 64-bit and you're looking to call the 32-bit PowerShell host.
You can also shorten the environment variable checking by using .NET:
if ([System.Environment]::Is64BitProcess) { @("yadda", "yadda") };
Cheers,
Lain