How do I change Powershell Execution Policy silently from a batch script?
The instructions below contain steps that tell you how to modify the registry. However, serious problems might occur if you modify the registry incorrectly.
Therefore, make sure that you follow these steps carefully. For added protection, back up the registry before you modify it. Then, you can restore the registry if a problem occurs.
For more information see How to back up and restore the registry in Windows.
reg add HKLM\system32\windows\microsoft\powershell\1\shellids\microsoft.powershell /v "Path" /d "c:\windows\system32\windowspowershell\v1.0\powershell.exe"
reg add HKLM\system32\windows\microsoft\powershell\1\shellids\microsoft.powershell /v "ExecutionPolicy" /d "unrestricted"
regedit /s file.reg
file.reg contains the following:
When a filename is specified on the command line, this switch is used to suppress any informational dialog boxes that would normally be displayed. This is useful when the Setup program for an application wants to execute REGEDIT.EXE with a .REG file, but does not want the user to be confused by any dialog boxes that are displayed.
- An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
- reg - Read, Set or Delete registry keys and values, save and restore from a .REG file.
- regedit - Import, export or delete registry settings from a text (.REG) file.
- regedit - Command-line switches.