Powershell Get-Itemproperty returns wrong value
Hello all,
I am working on a script to test computers for compliance to a set of specifications.
One of these is that the computer must have the Powershell executionpolicy set to "Remotesigned".
This is that part of the script:
$policy=Get-ItemProperty HKLM:\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell -Name ExecutionPolicy
$policy32=Get-ItemProperty HKLM:\SOFTWARE\WOW6432Node\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell -Name Executionpolicy
The problem is that $policy returns "Unrestricted" even if the registry says otherwise:
Also, Get-ExecutionPolicy run locally returns "RemoteSigned" as it should.
The script is pushed to the computer by a MDM program and is executed as SYSTEM, 64-bit.
When run locally as administrator, it produces the correct result.
Unfortunately I am stuck running with SYSTEM and can't run as any other user.
I've drawn the conclusion that the execution as SYSTEM has something to do with it but I can't figure out how and why. Any ideas?