When we try to run the powershell script on the Windows PowerShell or Sharegate PowerShell, we might come across the below error:
“.ps1 cannot be loaded because running scripts is disabled on this system.”
WINDOWS POWERSHELL EXECUTION POLICIES prevents running of all script files, including:
- formatting and configuration files (.ps1xml),
- module script files (.psm1), and
- Windows PowerShell profiles (.ps1)
Use the below command to get the Execution Policies, it gives the policies list and its scope.
Get-ExecutionPolicy –List
Here, we can see that all policies are set to undefined, if the execution policy in all scopes is Undefined
, the effective execution policy is Restricted
, which is the default execution policy.
That is the reason we are not able to run the scripts. To enable, we have to modify/set the execution policy, for this, use the below command:
Set-ExecutionPolicy unrestricted
This command removes the restriction policy for the Local Machine scope. It gives a prompt message, click on OK to accept the changes in policy. We have successfully modified the restriction policy.
Now, check the policies by using the below command:
Get-ExecutionPolicy –List
You can see that the Local Machine scoped execution policy has changed to “Unrestricted
”. Even you can see that we were able to run the PowerShell command without any problems.