我在更改Windows Server 2008+操作系统中的执行策略时遇到问题。 这是我第一次尝试运行我需要资源完全访问权限的脚本,并且在高级模式下启动Powershell后,我尝试以下方法:
Set-ExecutionPolicy Unrestricted
但是我得到这个:
Set-ExecutionPolicy:Windows PowerShell更新了您的执行策略
成功,但是这个设置被一个更多的策略所覆盖
具体范围。 由于重写,你的shell将保持其当前
RemoteSigned的有效执行策略。 input“Get-ExecutionPolicy -List”
查看您的执行策略设置。 欲了解更多信息,请参阅
“Get-Help Set-ExecutionPolicy”。
在行:1 char:1
+ Set-ExecutionPolicy不受限制
+ ~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo:PermissionDenied:(:) [Set-ExecutionPolicy],SecurityException
+ FullyQualifiedErrorId:ExecutionPolicyOverride,Microsoft.PowerShell.Commands.SetExecutionPolicyCommand
虽然我是pipe理员,但我无法更改执行策略。 该怎么办?
Ruby系统在Windows环境variables中调用
如何获得LAN上的活动IP地址,MAC地址和NetBIOS名称列表?
Power Shell的环境variables
定期自动下载Cacti Weathermap
检测IPv6是否在Windows机器上启用
我怎样让我的控制台窗口出现在不同的位置?
如何在我的Surface RT上卸载Staged App Package?
具有IdentityReference:BUILTIN Users的文件夹的列表
在Windows上设置docker时出错
该错误消息表明您尝试通过Set-ExecutionPolicy定义的Set-ExecutionPolicy被另一个作用域中的设置覆盖。 使用Get-ExecutionPolicy -List来查看哪个范围具有哪个设置。
PS C:> Get-ExecutionPolicy -List Scope ExecutionPolicy ----- --------------- MachinePolicy Undefined UserPolicy Undefined Process Undefined CurrentUser Undefined LocalMachine RemoteSigned PS C:> Set-ExecutionPolicy Restricted -Scope Process -Force PS C:> Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force Set-ExecutionPolicy : Windows PowerShell updated your execution policy successfully,but the setting is overridden by a policy defined at a more specific scope. Due to the override,your shell will retain its current effective execution policy of Restricted. Type "Get-ExecutionPolicy -List" to view your execution policy settings. ... PS C:> Get-ExecutionPolicy -List Scope ExecutionPolicy ----- --------------- MachinePolicy Undefined UserPolicy Undefined Process Restricted CurrentUser Unrestricted LocalMachine RemoteSigned PS C:> .test.ps1 .test.ps1 : File C:test.ps1 cannot be loaded because running scripts is disabled on this system. ... PS C:> Set-ExecutionPolicy Unestricted -Scope Process -Force PS C:> Set-ExecutionPolicy Restricted -Scope CurrentUser -Force Set-ExecutionPolicy : Windows PowerShell updated your execution policy successfully,your shell will retain its current effective execution policy of Restricted. Type "Get-ExecutionPolicy -List" to view your execution policy settings. ... PS C:> Get-ExecutionPolicy -List Scope ExecutionPolicy ----- --------------- MachinePolicy Undefined UserPolicy Undefined Process Unrestricted CurrentUser Restricted LocalMachine RemoteSigned PS C:> .test.ps1 Hello World!
正如你所看到的,尽管有错误,两个设置都被定义了,但更具体的作用域( Process )中的设置仍然优先,阻止或允许脚本执行。
由于默认作用域是LocalMachine所以错误可能是由CurrentUser或Process作用域中的设置引起的。 但更常见的原因是脚本执行是通过组策略(本地或域)配置的。
本地组策略可以由本地管理员通过gpedit.msc (本地组策略编辑器)进行修改,如本答案中所述 。
域组策略不能被本地设置/策略取代,必须由域管理员通过域控制器上的gpmc.msc (组策略管理)更改。
对于本地策略和域策略,可以将设置定义为计算机设置:
Computer Configuration `-Administrative Templates `-Windows Components `-Windows PowerShell -> Turn on Script Execution
或作为用户设置:
User Configuration `-Administrative Templates `-Windows Components `-Windows PowerShell -> Turn on Script Execution
前者适用于计算机对象,后者适用于用户对象。 对于本地策略,用户策略和计算机策略之间没有显着差异,因为用户策略会自动应用于计算机上的所有用户。
策略可以具有以下三种状态之一(或者,如果您计算可用于单独启用状态的3种设置,则为五种状态):
未配置 :策略不控制PowerShell脚本执行。
启用 :允许执行PowerShell脚本。
仅允许签名的脚本 : 只允许执行签名脚本(与Set-ExecutionPolicy AllSigned相同)。
允许本地脚本和远程签名脚本 :允许从远程位置(与Set-ExecutionPolicy RemoteSigned相同)执行所有本地脚本(已签名或未签名)和签名脚本。
允许所有脚本 :允许执行本地和远程脚本,不管它们是否被签名(与Set-ExecutionPolicy Unrestricted相同)。
禁用 :禁止执行PowerShell脚本(与Set-ExecutionPolicy Restricted相同)。
当本地和域策略设置为“ 未配置” (执行策略在作用域MachinePolicy和UserPolicy Undefined ,通过Set-ExecutionPolicy所做的更改才会生效。
问题是Windows不允许所有脚本以Unrestricted模式执行。 实际上,无论您的用户(即使是管理员)的执行策略, Local Group Policy将优先。
默认情况下,本地组脚本执行策略是不允许执行脚本的。 我们需要改变它!
更改本地组执行策略
我们通过Local Group Policy Editor执行此操作,您可以通过在Windows搜索栏中搜索“组策略”来访问Local Group Policy Editor 。 或者这样做:
按Win + r并输入命令mmc打开管理控制台。
转到File -> Add Remove Snap In...
在左窗格中找到Group Policy Object Editor并添加它。
关闭表格。
然后在左侧窗格中,可以扩展组编辑器。 展开它并导航到Computer Configuration -> Administrative Templates -> Windows Components 。
然后到Windows PowerShell 。
所以选择Turn on Script Execution 。 将配置更改为“已Enabled并指定“ Allow all scripts Execution Policy Allow all scripts Execution Policy 。
点击Ok确认并关闭管理控制台。
现在可以安装修补程序:
2.8.7 VS 2013: https : //github.com/NuGet/Home/releases/download/2.8.7/NuGet.Tools.vsix
3.1.1 for VS 2015: https : //github.com/NuGet/Home/releases/download/3.1.1/NuGet.Tools.vsix
https://github.com/NuGet/Home/issues/974
如果您最近在visual studio 2015中遇到了这个问题,请检查nuget包管理器在工具>扩展和更新>
如果PowerShell ExecutionPolicy是由域控制器通过组策略设置的,那么每次启动后都必须在注册表中将ExecutionPolicy重置为“绕过”。 我创建了一对启动脚本来自动执行这个过程。 下面,我描述我的过程。
创建一个名为%USERPROFILE% Documents StartupScripts的文件夹,然后将下面的代码放在名为ExecutionPolicy.ps1的PowerShell脚本中:
Push-Location Set-Location HKLM:SoftwarePoliciesMicrosoftwindowsPowerShell Set-ItemProperty . ExecutionPolicy "Bypass" Pop-Location
然后创建一个名为%USERPROFILE% AppData Roaming Microsoft Windows Start Menu Programs Startup Startup.cmd的文件,并在其中放置以下代码:
PowerShell -Version 3.0 -Command "Set-ExecutionPolicy Unrestricted" >> "%TEMP%startupLog.txt" 2>&1 PowerShell -Version 3.0 "%USERPROFILE%DocumentsstartupScriptsExecutionPolicy.ps1" >> "%TEMP%startupLog.txt" 2>&1
该脚本将在每次登录开始时运行。
创建以下ps.cmd并将其放在PATH中:
POWERSHELL -Command "$enccmd=[Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes((Get-Content '%1' | Out-String)));POWERSHELL -EncodedCommand $enccmd"
现在你可以运行任何PowerShell脚本,如下所示:
psa mypowershell.ps1
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。