Error when Executing a PowerShell Script for the First Time

When you are executing a PowerShell script for the first time you may encounter the following error:

.... cannot be loaded because running scripts is disabled on this system.

Why did this happen:

PowerShell Execution Policies

PowerShell has four execution policies for executing the script. Those four policies are described below:

Restricted

This is a default policy. If you use this policy, PowerShell won't execute any script.

Unrestricted

PowerShell will execute all scripts (local or downloaded from the Internet).

RemoteSigned

PowerShell will execute all local scripts (It will execute Internet downloaded scripts if they have a digital signature).

AllSigned

PowerShell will only run scripts which have a proper digital signature.

Solution

To resolve this issue, follow these steps:

Step 1. Open a PowerShell with elevated privileges.

Step 2. Execute the following command

Set-ExecutionPolicy RemoteSigned

Step 3. When you are prompted, press Y

Set PowerShell privileges for a script