【问题标题】:Permissions to run PowerShell scripts运行 PowerShell 脚本的权限
【发布时间】:2014-06-08 22:55:13
【问题描述】:

我们正在运行 PowerShell 脚本作为我们在 TeamCity 中自动构建的一部分,但它失败并出现以下错误:

[16:31:49][Step 1/1] File F:\<path>\sript.ps1 cann

[16:31:49][Step 1/1] ot be loaded because the execution of scripts is disabled on this system. Pleas

[16:31:49][Step 1/1] e see "get-help about_signing" for more details.

我在这台机器上将执行策略设置为Unrestricted

PS C:\> Get-ExecutionPolicy
Unrestricted

我可以从 PS 控制台手动运行同样的脚本,只是从 TeamCity 执行失败。有什么想法吗?

EDIT: As requested:
PS C:\Users\xxx> Get-ExecutionPolicy -List

                                                      Scope                                             ExecutionPolicy
                                                      -----                                             ---------------
                                              MachinePolicy                                                   Undefined
                                                 UserPolicy                                                   Undefined
                                                    Process                                                   Undefined
                                                CurrentUser                                                   Undefined
                                               LocalMachine                                                Unrestricted

【问题讨论】:

  • @jscott,请看编辑

标签: powershell teamcity


【解决方案1】:

正如@Duncan 所建议的,问题在于机器策略未定义。此设置只能通过组策略更改。在组策略中,导航到计算机配置 |管理模板 | Windows 组件 | Windows PowerShell 并配置打开脚本执行设置并选择执行策略。

更多详情:http://www.techrepublic.com/blog/the-enterprise-cloud/set-the-powershell-execution-policy-via-group-policy/

【讨论】:

    【解决方案2】:

    执行策略有三个作用域:进程、当前用户、本地机器。听起来您可能已经覆盖了您自己的用户 ID 而不是机器的执行策略,并且 TeamCity 可能以不同的用户身份运行。

    正如@jscott 在他的评论中所说,你应该这样做:

    Get-ExecutionPolicy -List
    

    获取执行策略的完整列表。特别要检查 LocalMachine 的设置。

    顺便说一句,Unrestricted 是一个糟糕的选择。 RemoteSigned 更好,因为它允许本地创建的脚本在未签名的情况下运行,但需要对从 Web 下载的任何脚本进行签名。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-24
      • 1970-01-01
      • 2021-06-22
      • 2015-12-05
      • 2023-01-19
      • 2014-06-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多