Windows 7 上的 PowerShell:为普通用户设置执行策略 [英] PowerShell on Windows 7: Set-ExecutionPolicy for regular users
问题描述
我想以普通用户身份在 Windows 7 上运行 PowerShell 脚本.每当我尝试时,我都会收到以下错误:
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
尝试通过 Set-ExecutionPolicy Unrestricted
解决失败:
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
我可以以管理员身份运行 Set-ExecutionPolicy Unrestricted
命令,但这似乎不会传播给非管理员用户.
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?
推荐答案
如果您(或乐于助人的管理员)以管理员身份运行 Set-ExecutionPolicy
,则将为所有用户设置该策略.(我建议使用remoteSigned"而不是unrestricted"作为安全措施.)
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.)
注意:在 64 位操作系统上,您需要分别为 32 位和 64 位 PowerShell 运行 Set-ExecutionPolicy
.
NB.: On a 64-bit OS you need to run Set-ExecutionPolicy
for 32-bit and 64-bit PowerShell separately.
这篇关于Windows 7 上的 PowerShell:为普通用户设置执行策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!