Change Powershell Execution Policy silently from Batch script

command linepowershell

I would like some help on setting a registry value for powershell. The path is

[hkey_local_machine\system32\windows\microsoft\powershell\1\shellids\microsoft.powershell]
"Path"="c:\windows\system32\windowspowershell\v1.0\powershell.exe"
"ExecutionPolicy"="unrestricted"

Since I have imported this from a known good machine,when I run the .reg file it works fine. But I would like this in a batch file.

When I manually call the command prompt, drop in the path e.g c:\powershell.reg, this imports the values and overwrites the the registry settings as required.
However if l call do the same thing in a batch file, the values are not changed in the registry
Using the reg add command in a batch file the values does not work.

Best Answer

Why not simply run the following via CMD

powershell -command "& {Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force}"

or this directly in Powershell (that's what the command is for after all):

Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force
Related Question