Dan*_*ton 61 powershell windows-7
我想以普通用户身份在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
Run Code Online (Sandbox Code Playgroud)
尝试解决via 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
Run Code Online (Sandbox Code Playgroud)
我可以Set-ExecutionPolicy Unrestricted以管理员身份运行该命令,但这似乎不会传播给非管理员用户.
如何以非管理员身份成功运行脚本?
Ste*_*ngs 111
Set-ExecutionPolicy Unrestricted -Scope CurrentUser
Run Code Online (Sandbox Code Playgroud)
这将为当前用户(存储在HKEY_CURRENT_USER中)而不是本地计算机(HKEY_LOCAL_MACHINE)设置执行策略.如果您没有对计算机的管理控制,这将非常有用.
Ric*_*ard 63
如果您(或有用的管理员)Set-ExecutionPolicy以管理员身份运行,则将为所有用户设置策略.(我建议使用"remoteSigned"而不是"unrestricted"作为安全措施.)
注意:在64位操作系统上,您需要分别运行Set-ExecutionPolicy32位和64位PowerShell.
小智 7
这应该可以解决您的问题,您应该尝试运行以下命令:
\n\nSet-ExecutionPolicy\xc2\xa0-ExecutionPolicy\xc2\xa0RemoteSigned\xc2\xa0-Scope\xc2\xa0CurrentUser\xc2\xa0\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
105532 次 |
| 最近记录: |