0

I just installed the latest version of PowerGUI (3.6.0.21).

When I try to run any script from inside PowerGUI I get the error message 'The file C:\Sandbox\MyPowerShell.ps1 cannot be loaded. The file C:\Sandbox\MyPowerShell.ps1 is not digitally signed.

I have googled all over for something simple to get around this, but no luck. What do I need to do to get this going?

Also, if I run the script commands from PowerShell directly they work.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mike Cheel
  • 12,626
  • 10
  • 72
  • 101
  • Is the execution policy of your system set to `RemoteSigned` or less? Check with `Get-ExecutionPolicy`. – Ansgar Wiechers Jul 02 '13 at 19:56
  • I tried that and it says AllSigned which is not what I want I know. When I try Set-ExecutionPolicy from powershell itself I either get error about not having access to a registry key or it appears successful when run as admin (UAC). Is there a way to set it without having to go to the registry key (inside powergui I mean)? – Mike Cheel Jul 02 '13 at 20:00
  • No, `Set-ExecutionPolicy RemoteSigned` or `Set-ExecutionPolicy Unrestricted` is the correct way to go about this. You normally don't need admin privileges for changing this setting, since it's user-specific. If you get an error (which exactly?) it usually means that an admin locked the setting with a local or domain policy. – Ansgar Wiechers Jul 02 '13 at 20:03
  • I'm a local admin (although not immune to company policies). I'll see if I can alter the key itself and respond back. – Mike Cheel Jul 02 '13 at 20:04
  • When I do a Get-ExecutionPolicy at the powershell console it gives me what I am looking for. From inside PowerGUI even that doesn't work. I AM able to change the permissions on the key in the registry. – Mike Cheel Jul 02 '13 at 20:10
  • I don't sit in front of your computer, so you need to tell me what you see. What is the ouptut of `Get-ExecutionPolicy` and `Set-ExecutionPolicy` in both PowerShell and PowerGUI? What errors (exactly) do you get? Please update your question with these informations. – Ansgar Wiechers Jul 02 '13 at 20:14
  • I understand that. From inside PowerGUI I get the error message in my opening question. From admin and regular user at the regular powershell prompt I get RemoteSigned. – Mike Cheel Jul 02 '13 at 20:15
  • @AnsgarWiechers is right - it is a execution policy thing. But the policy doesn't impact your interactive session so that is why you can run it in command line. Usually "Remotesigned" is the best one for most environment. If the environment is small or highly trusted then you can go "Unrestricted". You can test it using the command in this link http://stackoverflow.com/questions/9271681/how-to-run-powershell-script-even-if-set-executionpolicy-is-banned. Use it just for test to see if execution policy is the cause. – Peter Jul 02 '13 at 20:34
  • @Peter I can change the execution policy from the command line in both admin and non-admin capacity from the powershell console. Both state that I am using RemoteSigned. It's in PowerGUI that none of this seems to be taking hold. – Mike Cheel Jul 02 '13 at 20:40
  • @MikeCheel could you check out this link: http://security.stackexchange.com/questions/1801/how-is-powershells-remotesigned-execution-policy-different-from-allsigned. Maybe MyPowerShell.ps1 is copied over from somewhere else without signed by a trusted publisher? – Peter Jul 02 '13 at 21:28

1 Answers1

-1

AllSigned will not let you run an unsigned script. If you can't change the execution policy then import it as a module.

Save the script as a .psm1 and use Import-Module. It will bypass scripting policy because it's being loaded/run as a module.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • * the other comments are correct though- allsigned will not let you run an unsigned script.., if you can't change the execution policy then import it as a module. – TheITGuy Jun 29 '15 at 20:36