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.

 

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

  1. what can i do warning:file c:\windowspowershell\v1.0\modules\psdiagnostics.psm1 cannot be loaded because the execution of scripts is disabled on this system.please see “get-help about_signing”for more details.

  2. I read a lot of interesting content here. Probably you spend
    a lot of time writing, i know how to save you a lot of time,
    there is an online tool that creates readable, SEO
    friendly posts in seconds, just search in google – laranitas free content source

  3. I see a lot of interesting articles on your website.
    You have to spend a lot of time writing, i know how to save you a lot of work, there
    is a tool that creates unique, google friendly articles in couple of minutes, just type in google –
    k2 unlimited content

  4. I tried the live USB thing on utunbu website and it took over my windows 7 starter to where I couldn’t use it anymore we’ll I got it to go back to windows and now I’m getting the same waring about windowspowershell can run a script what is this and should I deny it or I’m not sure what or how to do this utunbu was all about commands n I don’t know nothing about that stuff please help me thanks

  5. I’m getting the same problem with this warning windowspowershell\v1.0\modules\psdiagnostics.psm1 can’t be signed, I tried lastnight 3/14/14 to fix my android tab and tried doing the live USB thing from utunbu website and all these commands started going I have no clue what it was doing but it took over my windows 7 starter and I couldn’t get into windows but now I can and now this pops up what do I do or put to block this

  6. HI Chris,
    I can only think of 2 things that possibly happened:
    1) the Lync powershell script has been changed by something/someone. Therefor the script is not signed anymore
    2) A patch/hotfix/application changed your ExecutionPolicy. However this sounds very unlikely to me.

    Nevertheless, good to know my post fixed your problem!

    1. I tried the live USB on Ubuntu put there commands on my laptop how can I stop this please help website to fix my android we’ll I have no knowledge of this web but I know it’s lynx well it’s all about command nothing that I know, anyway it took over my windows and I finally am able to get back into my windows but now I’m getting same warning I’m thinking Ubuntu

  7. Forgot to say I ran the ExecutionPolicy cmdlet within the Lync Server management Shell and it worked straight away (logged in as Administrator, run as administrator)

  8. Thank you very much man. For some reason I came in this morning and opened up lync powershell and it was saying something along the lines of the error you saw, and running the code for unrestricted worked a treat.
    Any ideas why this setting would suddenly change? I used the shell literally last night. Odd!

  9. 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?

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

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

      2. Hiwhen I run the suggested cmamonds 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? Shiran

      3. Hi Bota, are you sure you’re running the command as admin? The key will be autmatically created if it doesn’t exist yet.
        Make sure you open the powershell console as “Run as administrator”. (rightclick on the powershell shortcut)

  11. 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.

  12. 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();

  13. 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?

    1. 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!).

  14. 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

  15. 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.

    1. 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-

Leave a Reply

Your email address will not be published.