Bart's Weblog

Just a blog…

PowerShell: ExecutionPolicy

Posted by bartvdw on 2222/0404/2008

I know I waited far too long to start working with PowerShell. But OK, here we are. And immediately encountered something. By default it sets some security related to running scripts. Only when I did what it said, I was unable to change that security!

OK in short, after you install PowerShell, it sets the “ExecutionPolicy” for scripts to “Restricted”, which means you’re not allowed to execute scripts. Not very interesting… So I used the “Set-ExecutionPolicy RemoteSigned” command to change, but this returned an 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  <<<< RemoteSigned

  • Open registry
  • Browse to key HKLM\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell
  • If “ExecutionPolicy” does not exist, create it as REG_SZ with value “RemoteSigned”
  • Open PowerShell and use the command “Get-ExecutionPolicy” to see it is done correctly

It’s only obvious that if another security level is desired, you adapt the value… :-)

About these ads

14 Responses to “PowerShell: ExecutionPolicy”

  1. Jesse said

    You *do not* need to do anything in the registry… Editing the registry is not the proper process to change this policy.

    Just running the following command is *all* that you need to do:

    PS> set-executionpolicy remotesigned

  2. Jesse said

    You need to be running PowerShell as an Administrator to change the ExecutionPolicy. That is why you got access denied…

    • Drew said

      I’m running the dang thing as an Administrator and it still refuses to let me change the ExecutionPolicy. Seems like a stupid code-block to me.

  3. Bobby said

    Jesse, not correct- even as administrator you get this error.. Going directly to the registry, however, works and you are now able to change the executionpolicy.

    Thanks!

  4. John said

    I had the same issue, ran ps2 as admin ,and did the set-executionPolicy remotesigned, and it worked.

    Thanks,
    John

  5. Kyle said

    This is exactly what I needed. THANK YOU!

  6. [...] pages for troubleshooting: http://technet.microsoft.com/en-us/library/ee176949.aspx http://bartvdw.wordpress.com/2008/04/22/powershell-executionpolicy/#comment-190 No Comments by Kyle on March 8, 2011  •  Permalink Posted in [...]

  7. Kyle said

    I resummarized this on my blog, if this helps anyone:

    http://kyleclegg.com/powershell/

    Good luck!

  8. [...] [...]

  9. vinithra said

    hi, can anybody help me out…pls….i have a unix system and a windows2008 server….im doing ssh from the unix system to the windows server and then trying to execute a powershell script….its saying “File C:\Users\sveaisrvcd\Documents\MyScripts\Hello.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see “get-help about_signing” for more details.”. And i checked the execution-policy which shows ‘restricted’, but it is unrestricted when i check on the system directly….how can i solve this….pls help…
    thanks in advance..

  10. Tihamer said

    Nothing worked for me (even though i was running PowerShell as administrator, AND I have administrator privileges).
    I didn’t want to add the ExecutionPolicy key to my registry, so I changed registry privileges by:
    Running regedit
    Going to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell
    Right-Clicking to Permissions
    Selecting and granting “Full Control” privileges to Users.

    It worked!
    (thanks to RW.be at http://answers.microsoft.com/en-us/windows/forum/windows_7-windows_programs/access-to-the-registry-key-for-powershel-is-denied/9e5cb142-ee69-e011-8dfc-68b599b31bf5)

  11. Jeff said

    You will need to do it as administrator for both the 64bit and 32bit versions of Powershell.

  12. […] This post explains how to edit the registry directly. […]

  13. McBrosa said

    If none of those works try running this as admin…

    Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned

    For more detail:

    http://absoblogginlutely.net/2010/03/enabling-powershell-to-run-scripts-with-registry-permissions/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: