I need to find out the powershell (versions 4 and 5+) execution policy without using powershell itself
I tried to look into registry - HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell
I found ExecutionPolicy value in two keys, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell and HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\ScriptedDiagnostics
The first one corresponded to the policy given by executing Get-ExecutionPolicy cmdlet, but on some servers in our environment the value is missing. Is there any other, 100% reliable, way to check the policy without using Powershell itself?
No key would equal Undefined
If the execution policy in all scopes is Undefined, the effective execution policy is Restricted, which is the default execution policy.
x64
Current User
HKCU\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell : ExecutionPolicy
Local Machine
HKLM\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell : ExecutionPolicy
x86
Local Machine
HKLM\SOFTWARE\WOW6432Node\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell : ExecutionPolicy
Machine Policy
HKLM\Software\WOW6432Node\Policies\Microsoft\Windows\PowerShell : ExecutionPolicy
User Policy
HKCU\Software\Policies\Microsoft\Windows\PowerShell : ExecutionPolicy