Windows 7 Windows 7上的PowerShell:为普通用户设置执行策略

Windows 7 Windows 7上的PowerShell:为普通用户设置执行策略,windows-7,powershell,Windows 7,Powershell,我想作为普通用户在Windows7上运行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

我想作为普通用户在Windows7上运行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
命令,但这似乎不会传播到非管理员用户

如何以非管理员身份成功运行脚本?

如果您(或有帮助的管理员)以管理员身份运行
Set ExecutionPolicy
,则将为所有用户设置策略。(我建议将“远程签名”而不是“无限制”作为安全措施。)

注意:在64位操作系统上,您需要分别为32位和64位PowerShell运行
Set ExecutionPolicy

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
这将为当前用户(存储在HKEY_current_user中)而不是本地计算机(HKEY_local_machine)设置执行策略。如果您没有对计算机的管理控制,这将非常有用


RemoteSigned
是一种比
无限制
更安全的执行策略。如果下载脚本时,
RemoteSigned
阻止您执行该脚本,则在检查脚本后,通过打开文件属性并标记“Unblock”来删除限制。如果这是不可行的,那么您可以将策略设置为
不受限制的

这将解决您的问题,您应该尝试运行以下操作:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser 

通过PowerShell运行此命令。它对我有效,希望对你也有效:)

我已经尝试过了-将事情设置为
不受限制的
,因为管理员似乎对非管理员没有任何改变…@DanVinton:然后发生了其他事情。建议再次设置为admin,然后从admin和普通shell中检查
Get ExecutionPolicy
。有可能是集团政策推翻了你的愿望。按照通常的It方式,有人(众所周知)在你身后看着你,这就解决了问题。。。谢谢对于64位Windows 8,必须从提升的PowerShell窗口执行一条注释,如下所示:
Set ExecutionPolicy RemoteSigned-Force
后跟
start job{Set ExecutionPolicy RemoteSigned-Force}-RunAs32
。这是确保两个版本都被寻址的唯一方法。谢谢,@Darek!由于执行政策每次都返回AllSigned,我几乎要把头发撕成碎片。不,它终于坚持住了,耶!完美的这立刻解决了我的问题。对于新用户来说,powershell被宣传为一种默认不允许脚本的脚本语言,这有点令人沮丧。“不受限制”?请注意。此
Set ExecutionPolicy Unrestricted-Scope CurrentUser
命令解决了我的问题。❤
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser 
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser