Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The Execution Policy is a safety feature which prevents scripts from running on the machine. The default policy on all new Windows OS's is Restricted which prevents all scripts from running on the machine.  As such, you will have to change the policy before running any powershell scripts.

Set-ExecutionPolicy -ExecutionPolicy Bypass 

The above line allows all scripts to run but it alters the settings for the entire machine. You can specify how far the policy is implemented however.

Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope CurrentUser will allow scripts to run for the user.

Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process will allow scripts to run for the current Powershell session and will not affect current policy settings.

Unfortunately, all the above require a powershell console to be open and the lines typed manually. To get around this we can use the command lilne.

Start powershell.exe -ExecutionPolicy Bypass -File "path\to\File.ps1"

Running the above line from an admin level command line will run powershell as admin, then from the powershell instance, it will run whatever .ps1 file you give it. Additionally, it won't alter the default policies set for the machine or user.