KB ID 0001417
Problem
If you’ve arrived here, you are trying to run a script, and you cant;
[box]PS C:\Users\{User-name}> .\{script-name}.ps1
.\{script-name} : File C:\Users\{User-name}\{script-name} cannot be loaded because running scripts is
disabled on this system. For more information, see about_Execution_Policies at
http://go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ .\{script-name}
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
PS C:\Users\\{User-name}>[/box]
Solution
Execute the following command;
[box]Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass[/box]
Then run your script.
THIS WILL ONLY WORK: While that PowerShell window is open, so don’t close it if you are running a lot of scripts.
I Want to Always be Able to Run Scripts?
OK you can either change the ‘Scope’ of that last command, from ‘Process’ to to ‘CurrentUser’, or ‘CurrentMachine’.
- Process: The execution policy affects only the current Windows PowerShell process.
- CurrentUser: The execution policy affects only the current user.
- LocalMachine: The execution policy affects all users of the computer.
Or you can simply change the policy ‘Globally’;
[box]Set-ExecutionPolicy {Value}[/box]
Possible values are;
- Restricted: Does not load configuration files or run scripts. Restricted is the default execution policy.
- AllSigned: Requires that all scripts and configuration files be signed by a trusted publisher, including scripts that you write on the local computer.
- RemoteSigned: Requires that all scripts and configuration files downloaded from the Internet be signed by a trusted publisher.
- Unrestricted: Loads all configuration files and runs all scripts. If you run an unsigned script that was downloaded from the Internet, you are prompted for permission before it runs.
- Bypass: Nothing is blocked and there are no warnings or prompts.
- Undefined: Removes the currently assigned execution policy from the current scope. This parameter will not remove an execution policy that is set in a Group Policy scope.
Related Articles, References, Credits, or External Links
NA