目标计算机上的PowerShell-TFS任务,更改远程服务器中的执行策略后,安全警告仍然存在



我很紧张,因为我不知道在我发布的版本中,目标机器任务(v1.0和2.0(上的powershell会发生什么。每次我运行任务时,它都会给我一个错误:

AuthorizationManager check failed. ---> System.Management.Automation.PSSecurityException: AuthorizationManager check failed. ---> System.Management.Automation.Host.HostException: A command that prompts the user failed because the host program or the command type does not support user interaction. The host was attempting to request confirmation with the following message: Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your computer. If you trust this script, use the Unblock-File cmdlet to allow the script to run without this warning message. Do you want to run \serverc$Program Filesexampleps.ps1?

我知道这可能与执行策略有关,所以这就是我迄今为止试图解决的问题:

  1. 我进入远程服务器,关闭了管理员的IE增强安全,因为运行此脚本的服务帐户是admin
  2. Shift+右键单击powershell以作为服务帐户运行,并将执行策略从remotesigned更改为bypass。在32位和64位powershell中都执行了此操作。旁路已设置为本地机器和当前用户
  3. 将\server\c$\Program Files\examples.ps1添加到internet选项下的受信任站点

我试过在谷歌上搜索和stackoverflow类似的问题,这些都是我发现的。

更新

在尝试了以上所有3种方法后,即使我尝试直接在控制台中运行ps脚本,安全警告仍然会出现。由于某些原因,绕过执行策略没有生效。--我能够在控制台中运行它而没有发出警告,然而,tfs任务仍然失败了

我真的很沮丧,我希望社区里的任何人都能给我一些指导。

非常感谢。

请尝试以下方法看看它们是否可以工作:

  1. 使用";"旁路";执行策略标志

    PowerShell.exe -ExecutionPolicy Bypass -File serverc$Program Filesexampleps.ps1
    
  2. 在文件和管道中读取脚本到PowerShell标准

    Get-Content serverc$Program Filesexampleps.ps1 | PowerShell.exe -noprofile -
    
  3. 使用调用表达式命令

    Get-Content serverc$Program Filesexampleps.ps1 | Invoke-Expression
    
  4. 使用";无限制的";执行策略标志

    PowerShell.exe -ExecutionPolicy UnRestricted -File serverc$Program Filesexampleps.ps1
    

还有一些其他方法可以尝试。要查看更多详细信息,您可以参考">15种绕过PowerShell执行策略的方法";。

最新更新