Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell on Windows 7: Set-ExecutionPolicy for regular users

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?

like image 637
Dan Vinton Avatar asked Jan 10 '11 13:01

Dan Vinton


People also ask

How do I set default ExecutionPolicy?

The Set-ExecutionPolicy cmdlet's default scope is LocalMachine, which affects everyone who uses the computer. To change the execution policy for LocalMachine, start PowerShell with Run as Administrator. To display the execution policies for each scope in the order of precedence, use Get-ExecutionPolicy -List .

How do I set-ExecutionPolicy unrestricted Currentuser?

Select Start > All Programs > Windows PowerShell version > Windows PowerShell. For Remote Signed, run Set-ExecutionPolicy RemoteSigned . For Unrestricted, run Set-ExecutionPolicy Unrestricted .

Why is the default execution policy of Windows PowerShell is restricted?

The reason for the above error is a security setting built into Windows PowerShell called "execution policy". Execution Policy determines how (or if) PowerShell runs scripts. By default, PowerShell's execution policy is set to Restricted; this means that scripts will not run.


1 Answers

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.

like image 85
Stephen Jennings Avatar answered Oct 27 '22 08:10

Stephen Jennings