ITExperience.NET Rotating Header Image

File cannot be loaded because the execution of scripts is disabled on this system error in PowerShell



When you try to run a Powershell script (PS1), you may get the following error:

File xyz.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see “get-help about_signing” for more details. At line:1 char:2

The reason for this error is the security setting on your pc that does not allow you to execute a script.  This is the so-called Execution Policy. By default, the Execution Policy is set to Restricted. This setting means that you may not run any PS1 script at all.

An overview of the policy levels:

Restricted: Individual cmdlets can run, but not saved Powershell scripts. This is the default setting.
AllSigned: Scripts can run, but must have a digital signature even if written on the local computer. Prompts you before running scripts from trusted publishers.
RemoteSigned: Scripts written on the local computer do not need a digital signature, but any script downloaded from outside (email, IM, Internet) must have a signature to execute. 
Unrestricted: Any script can run, but scripts downloaded from outside will run with a warning.

If you’re working on a desktop and just experimenting with PowerShell, the best is to set the policy-level to Unrestricted. This allows you do everything with annoying security boundaries. Just be careful not to run every script you download from the internet :)
If you’re working in a production environment and only want to run self-written scripts, the RemoteSigned level should be loosy enough.

To change the Execution Policy to Unrestricted, type the following command in Powershell

Set-ExecutionPolicy Unrestricted

To change the Execution Policy to RemoteSigned (to run your own scripts), type the following command in Powershell

Set-ExecutionPolicy RemoteSigned

If you have any question left, feel free to leave a comment. By choosing to be informed when someone posts a reply, you will immediately receive an email after someone replies.

 

23 Comments

  1. Ronald says:

    Thanks, in our company it was solved by running the Powershell scripts from a bat file.

      (Quote)

  2. Seamari says:

    Just run it as an Administrator –> Run as administrator

      (Quote)

  3. Murali says:

    We are trying to run a Lync command using C#, its giving the same error mentioned by you.
    Event setting the execution policy to unrestricted doesn’t have any effect, an y alternative suggestions?

      (Quote)

  4. Faisal says:

    Thanx, dear….

      (Quote)

  5. Todd says:

    If you’re on a 64-bit machine, make sure you run set-executionpolicy both in the 64-bit Powershell and 32-bit one.

      (Quote)

    1. Anonymous says:

      It work, thanks!

        (Quote)

      1. robert nadar says:

        thanks it worked…
        we need to set the ExecutionPolicy to UnRestricted for both x86 and 64 version of Powershell

          (Quote)

    2. Eugene says:

      thanks it worked…
      we need to set the ExecutionPolicy to UnRestricted for both x86 and 64 version of Powershell

      Thanks buddy, it really helped!

        (Quote)

  6. ludo says:

    thanks for the info !

      (Quote)

  7. faisal says:

    thanks it worked for me as well

      (Quote)

  8. Vijay says:

    i’ve set my execution policy to Unrestricted and i’m able to run the scripts now. But when i call this ps1 scripts from another Nant scripts, it fails giving the same “execution disabled error”. how can i get this run from my nant script.

      (Quote)

  9. Anonymous says:

    thx,i have just run it and it resolved my issure

      (Quote)

  10. Faraz says:

    Hi,
    I have changed the policy level to Unrestricted but still getting the same error while running the script :s

      (Quote)

  11. Tommy says:

    I’m trying to run a Lync cmdlet from inside VS2010, and despite having Remotesigned set I get the same “Cannot be loaded…” error. The same happens if I try to run the built exe from a command window. I get the exception on the Open call:

    // Get the operating environment to run commands.
    InitialSessionState iss = InitialSessionState.CreateDefault();
    iss.ImportPSModule(new[] { “Lync” });
    using (Runspace myRunSpace = RunspaceFactory.CreateRunspace(iss))
    {
    myRunSpace.Open();

      (Quote)

  12. Shiran says:

    Hi

    when I run the suggested commands I get the following error:
    ————————————————————————
    Set-ExecutionPolicy : Access to the registry key ‘HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft
    .PowerShell’ is denied.
    At line:1 char:20
    + Set-ExecutionPolicy <<<< unrestricted
    + CategoryInfo : NotSpecified: (:) [Set-ExecutionPolicy], UnauthorizedAccessException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.SetExecutionPolicyCommand
    —————————————————————————–

    I looked for that registry key, but it's not there- the registry folder "Microsoft.PowerShell" has the keys: Default and Path only.

    any suggestions?

      (Quote)

    1. Christian says:

      Hi

      when I run the suggested commands I get the following error:
      ————————————————————————
      Set-ExecutionPolicy : Access to the registry key ‘HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft
      .PowerShell’ is denied.

      Hello Shiran,

      it looks like you do not have permissions to modify the registry key(s).
      When launching Powershell, try to right click and choose “Run as administrator”. This should give you the appropriate rights to edit.
      You probably face this problem, because you have enabled UAC on your computer (which is a good thing!).

        (Quote)

  13. Chaitanya Bhalerao says:

    Thanks a lot !!! very useful information.

      (Quote)

  14. Jimmy says:

    I run the (Set-ExecutionPolicy Unrestricted )and it worked fine ..that is

      (Quote)

  15. Kamil says:

    Thanks for the info, its help me a lot.

    BTW, make sure you run PowerShell as Administrator to execute Set-ExecutionPolicy

      (Quote)

  16. OmarOZ7 says:

    Changing Execution Policy

    The best way to set execution policy is to use the Set-ExecutionPolicy cmdlet. Set-ExecutionPolicy has one parameter – executionpolicy which can take one of four values:

    Restricted
    All Signed
    Remote Signed
    Unrestricted

    Alternatively it is possible to edit the following registry key

    HKEY_Local_Machine\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.Powershell\ExecutionPolicy

      (Quote)

  17. Dave says:

    LOL

    That is freaking hilarious. I bet this guy would lock keys in his glove-box so he has keys if he ever gets locked out of his car.

      (Quote)

  18. Roy says:

    How can you run a script which will allow scripts to run, if running a script is disabled in the first place?

    Fricken stupid-

      (Quote)

    1. stfukthx says:

      you run the command from the PS console (as admin) , after that you will be able to run .ps1 script files … get a clue , k thx

      How can you run a script which will allow scripts to run, if running a script is disabled in the first place?

      Fricken stupid-

        (Quote)

Leave a Reply