August 22, 2015

PowerShell - Running scripts is disabled on this system.

When you load a script file in PowerShell ISE and try to run that script, probably you will get this error:

File x.ps1 cannot be loaded because running scripts is
disabled on this system. For more information, see about_Execution_Policies at
http://go.microsoft.com/fwlink/?LinkID=135170. + CategoryInfo: SecurityError: (:) [], ParentContainsErrorRecordExcepti on + FullyQualifiedErrorId : UnauthorizedAccess


This is because the script is blocked from execution due to the execution policy. So you need to set it according to your requirements. For Example I set it as :
Set-ExecutionPolicy -Scope Process -ExecutionPolicy RemoteSigned
And I get my script worked, it allows the execution of script only for current process.

The Scope parameter could have following valid values:
  • Process: The execution policy affects only the current Windows PowerShell process.
  • CurrentUser: The execution policy affects only the current user.
  • LocalMachine: The execution policy affects all users of the computer.
The default is LocalMachine.

References:  https://technet.microsoft.com/en-us/library/hh849812.aspx

No comments:

Post a Comment