PowerShell on Windows 7: Set-ExecutionPolicy for regular users

Windows 7Powershell

Windows 7 Problem Overview


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?

Windows 7 Solutions


Solution 1 - Windows 7

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.

Solution 2 - Windows 7

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.

Solution 3 - Windows 7

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

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser 

Solution 4 - Windows 7

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Run this command through PowerShell. It works for me hope it will work for you also :)

Solution 5 - Windows 7

You can use this PowerShell command:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Solution 6 - Windows 7

RemoteSigned is safer execution policy than Unrestricted.

set-executionpolicy remotesigned

Solution 7 - Windows 7

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

Solution 8 - Windows 7

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDan VintonView Question on Stackoverflow
Solution 1 - Windows 7Stephen JenningsView Answer on Stackoverflow
Solution 2 - Windows 7RichardView Answer on Stackoverflow
Solution 3 - Windows 7John V Hobbs JrView Answer on Stackoverflow
Solution 4 - Windows 7prabhat.mishra2812View Answer on Stackoverflow
Solution 5 - Windows 7mustafa sungur taşView Answer on Stackoverflow
Solution 6 - Windows 7harun ugurView Answer on Stackoverflow
Solution 7 - Windows 7khannikkeyView Answer on Stackoverflow
Solution 8 - Windows 7DuffyView Answer on Stackoverflow