Enable Running PowerShell Scripts On This System
If you see an error similar to this when trying to run a PowerShell Script you might need to change the execution policy.
.\test1.ps1 : File C:\Users\user1\Desktop\test1.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170. At line:1 char:1 + .\test1.ps1 + ~~~~~~~~~~~ + CategoryInfo : SecurityError: (:) , PSSecurityException + FullyQualifiedErrorId : UnauthorizedAccess
From a PowerShell window, run this command to check if the policy is restricted or not.
If you see the following it means that it is restricted and will need to be updated.
You are probably going to need to run PowerShell with administrative permissions to change the execution policy.
- Right click on the PowerShell icon and select “Run as Administrator”.
From PowerShell, run this command to set the execution policy to “Unrestricted”.
Set-ExecutionPolicy -ExecutionPolicy Unrestricted
Verify that it has been set:
Try running a script: