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
I am trying to push the script through Platform scripts in Scripts and remediations in Devices on intune. Tried both user and system. Selected to run script in 64 bit Powershell host. For some users it is working and for some users not working. very strange.
Regards,
Ram
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
- LainRobertsonJun 28, 2024Silver Contributor
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
- Thihan_LinJul 04, 2024Copper ContributorThanks Lain. Appreciate your helpful mindset
- Rambo363636Jun 28, 2024Brass ContributorHi Thihan,
Thank you. I will test and let you know soon.
Cheers,
Ram- Thihan_LinJul 04, 2024Copper ContributorHey Rambo
Does it resolve?- Rambo363636Jul 19, 2024Brass ContributorThanks very much Thihan. It is resolved