Powershell Get-Itemproperty returns wrong value

Andreas Lundgren 1 Reputation point
2021-03-24T08:39:14.397+00:00

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:
81037-1.png

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?

Windows for business Windows Server User experience PowerShell
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.