Windows 7 上的 PowerShell:针对普通用户的 Set-ExecutionPolicy
我想以普通用户身份在 Windows 7 上运行 PowerShell 脚本。每当我尝试时,都会收到以下错误:
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
解决失败:
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 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这将为当前用户(存储在 HKEY_CURRENT_USER 中)而不是本地计算机(HKEY_LOCAL_MACHINE 中)设置执行策略。如果您对计算机没有管理控制权,这非常有用。
RemoteSigned
是比Unrestricted
更安全的执行策略。如果您下载了脚本,并且RemoteSigned
阻止您执行该脚本,则在审查该脚本后,通过打开文件的属性并标记“取消阻止”来删除限制。如果这是不可行的,那么您可以将该策略设置为Unrestricted
。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 thanUnrestricted
. If you download a script andRemoteSigned
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 toUnrestricted
instead.如果您(或乐于助人的管理员)以管理员身份运行
Set-ExecutionPolicy
,将为所有用户设置该策略。 (我建议使用“remoteSigned”而不是“unrestricted”作为安全措施。)注意:在 64 位操作系统上,您需要为 32 位和 64 位 PowerShell 运行
Set-ExecutionPolicy
分别地。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.这应该可以解决您的问题,您应该尝试运行以下命令:
This should solve your problem, you should try to run the following below:
如果您是电脑的管理员,则可以在 powershell 窗口中键入以下命令
。您可能必须以管理员身份运行 shell。
一旦你这样做了,它会要求你确认,
如果要为所有全局用户设置无限制设置,请输入“A”
如果您只想为当前用户(管理员)设置不受限制的设置,请输入“Y”
记住:- 您始终可以使用以下命令恢复所做的更改:
If your the administrator of your pc, you can type out the following command in your
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: