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, Ram.
In your screenshot, those commands are never going to work.
It seems as though you've copied-and-pasted the actual command as well as the prompt sitting in front of the command, and then tried to execute the combined value.
"PS" is an alias for Get-Process, hence the "weird" errors originating from PS.
As a final comment, the commands from your screenshot are nowhere to be found in your script, meaning the screenshot is of no use to us in its current form. We also cannot see the initial value of the variable "registryPath", meaning we can't even comment on the screenshot as a standalone exercise. It might simply be a case that the only error is with the commands you're trying to run.
Commenting purely on the script, there's nothing in it that would require administrative access.
I'm not an InTune expert, however, make sure this script runs in a user context and not a machine context, as it's not written with the latter in mind.
Cheers,
Lain
- Rambo363636Jun 26, 2024Brass ContributorHi Lain,
I agreed screenshot is wrong. But if i open powershell as administrator and run the script it will work and it will change the excel font to verdana. I have tried both user and machine context deploying in intune. It is working only for some devices and users.
Please let me know if i need to add anything into the above script.
Thanks.- LainRobertsonJun 26, 2024Silver Contributor
Technically, there's nothing wrong with the script meaning there's nothing PowerShell has to offer you. The issue you're facing is a permissions issue when accessing that particular area of the registry as it's locked down for use by the group policy engine - which makes sense. You have to resolve this requirement through InTune, not PowerShell.
The script will work just fine once the deployment rights issue is sorted out.
Have you tried asking this question in an InTune forum?
Cheers,
Lain
- Rambo363636Jun 27, 2024Brass ContributorHi Lain,
Thanks very much for confirming there is no issue in the script. I will see if any intune champ can assist.
Regards,
Ram