运行PowerShell脚本的权限

时间:2014-02-27 17:13:04

标签: powershell teamcity

我们正在运行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

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

执行策略有三个范围:Process,Current User,Local Machine。听起来您可能已经覆盖了自己的用户ID但不是机器的执行策略,而TeamCity可能是以不同的用户身份运行。

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

Get-ExecutionPolicy -List

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

BTW,Unrestricted是一个糟糕的选择。 RemoteSigned更好,因为它允许本地创建的脚本运行无符号,但需要签署从Web下载的任何脚本。

相关问题