This error comes when the PowerShell execution policy doesn’t allow us to run scripts. I also found the same error when tried to run a PowerShell script.
The PowerShell execution policy is default set to Restricted. You can change the PowerShell execution policies with
Set-ExecutionPolicy cmdlet. To run outside script set policy to RemoteSigned.
PS C:\> Set-ExecutionPolicy RemoteSigned
Below is the list of four different execution policies in PowerShell
- Restricted – No scripts can be run.
- AllSigned – Only scripts signed by a trusted publisher can be run.
- RemoteSigned – Downloaded scripts must be signed by a trusted publisher.
- Unrestricted – All Windows PowerShell scripts can be run.
You Should Also Know:
Run the following command to get current execution policy in set in PowerShell.
PS C:\> get-executionpolicy
You can bypass this policy by adding
-ExecutionPolicy ByPass when running PowerShell script.
c:\> powershell -ExecutionPolicy ByPass -File script.ps1