75

I want to run PowerShell scripts on Windows 7 as a regular user. Whenever I try, I get the following error:

File C:\Users\danv\Documents\WindowsPowerShell\profile.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
+ . <<<<  'C:\Users\danv\Documents\WindowsPowerShell\profile.ps1'
    + CategoryInfo          : NotSpecified: (:) [], PSSecurityException
    + FullyQualifiedErrorId : RuntimeException

Attempting to solve via Set-ExecutionPolicy Unrestricted fails:

PS C:\Users\danv> Set-ExecutionPolicy Unrestricted
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 can run the Set-ExecutionPolicy Unrestricted command as administrator, but this doesn't seem to propagate to non-administrator users.

How can I successfully run scripts as a non-administrator?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Dan Vinton
  • 26,401
  • 9
  • 37
  • 79

5 Answers5

145
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

This will set the execution policy for the current user (stored in HKEY_CURRENT_USER) rather than the local machine (HKEY_LOCAL_MACHINE). This is useful if you don't have administrative control over the computer.

RemoteSigned is a safer execution policy than Unrestricted. If you download a script and RemoteSigned is preventing you from executing it, then after vetting the script, remove the restriction by opening the file's properties and flagging "Unblock". If this is infeasible, then you can set the policy to Unrestricted instead.

Stephen Jennings
  • 12,494
  • 5
  • 47
  • 66
  • 3
    Perfect. This solved my problem immediately. It's sort of frustrating for new users that powershell is advertised as a scripting languague that by default disallows scripting. – Charles Clayton Aug 14 '14 at 20:53
  • 2
    "Unrestricted"? Be aware of [the security implications](http://stackoverflow.com/questions/4037939/powershell-says-execution-of-scripts-is-disabled-on-this-system/26955050#26955050). – Peter Mortensen Dec 01 '14 at 20:01
  • This `Set-ExecutionPolicy Unrestricted -Scope CurrentUser` command solved my problem.❤ – repleeka Mar 09 '21 at 19:11
69

If you (or a helpful admin) runs Set-ExecutionPolicy as administrator, the policy will be set for all users. (I would suggest "remoteSigned" rather than "unrestricted" as a safety measure.)

NB.: On a 64-bit OS you need to run Set-ExecutionPolicy for 32-bit and 64-bit PowerShell separately.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Richard
  • 106,783
  • 21
  • 203
  • 265
  • I've tried this - setting things to `Unrestricted` as Administrator doesn't seem to change anything for the non-administrator... – Dan Vinton Jan 10 '11 at 14:06
  • @DanVinton: Then something else is happening. Suggest setting as admin again, then checking `Get-ExecutionPolicy` from both admin and normal shells. It is possible Group Policy is overruling your wishes. – Richard Jan 10 '11 at 14:34
  • In the usual IT fashion, having someone (proverbially) looking over your shoulder has resolved it... thanks! – Dan Vinton Jan 10 '11 at 14:39
  • 20
    One comment for 64-bit Windows 8, you must execute it from an elevated PowerShell window like so: `Set-ExecutionPolicy RemoteSigned -Force` followed by `start-job { Set-ExecutionPolicy RemoteSigned -Force } -RunAs32`. That's the only way to ensure that both versions are addressed. – Darek Mar 12 '13 at 20:12
  • Thanks, @Darek ! I am close to tearing my hair out due to ExecutionPolicy returning to AllSigned *every time*. Not it finally sticks, yay! – pepoluan Jul 01 '13 at 05:08
7

This should solve your problem, you should try to run the following below:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser 
Tony Hinkle
  • 4,706
  • 7
  • 23
  • 35
John V Hobbs Jr
  • 397
  • 4
  • 5
0
Select ***Start > All Programs > Windows PowerShell version > Windows PowerShell***.
Type ```Set-ExecutionPolicy RemoteSigned``` to set the policy to ```RemoteSigned```.
Type ```Set-ExecutionPolicy Unrestricted``` to set the policy to ```Unrestricted```.
Type ```Get-ExecutionPolicy``` to verify the current settings for the execution policy.
Type ```Exit```.
khannikkey
  • 901
  • 6
  • 3
0

If your the administrator of your pc, you can type out the following command in your

 Set-ExecutionPolicy Unrestricted

powershell window. You might have to run the shell as an administrator.

Once you have done that, it will ask you for the confirmation, If you want to set the unrestricted setting for all the global users, enter 'A' If you want to set the unrestricted setting only for current user(Admin), enter 'Y'

Remember:- You can always revert the changes you made with the following command:

Set-ExecutionPolicy Restricted
Duffy
  • 123
  • 7