Thursday, June 03, 2010

Unable to run Powershell Scripts due to 'cannot be loaded because the execution of scripts is disabled on this system'

After having coded your Windows Powershell utility script, you happily tried running it but then either nothing get run or you get '...cannot be loaded because the execution of scripts is disabled on this system..' error.

Some research into Powershell reveals that PowerShell has this "execution policy" concept. The execution policy determines whether PowerShell can run scripts. The default execution policy is set to Restricted which means ALL scripts will NOT run.

To verify the current "execution policy", run the below on your Powershell command prompt:
Get-ExecutionPolicy

To enable running of scripts, you need to set "execution policy" to RemoteSigned.
Set-ExecutionPolicy RemoteSigned

There are other options available like AllSigned and Unrestricted but they shall not be discussed here.


The above shows a pictorial representation of how it could look like on a Powershell command prompt running the above instructions.

No comments:

Post a Comment

Do provide your constructive comment. I appreciate that.