【发布时间】:2019-02-28 18:51:22
【问题描述】:
在我的持续交付管道期间,我想运行 Powershell 脚本,该脚本启动用于更新数据库的 .NET Core 应用程序。问题是用户使用的 TFS 代理没有权限连接到 MSSQL 服务器。这就是为什么我想以不同的用户身份运行这个过程。我现在正在做的是
$username = 'DOMAIN\username'
$password = 'password'
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential -ArgumentList $username, $securePassword
Start-Process -FilePath 'dotnet' -ArgumentList 'MyApp.dll' -NoNewWindow -Wait -Credential $credential
运行此脚本会导致 Powershell 窗口冻结。我不能Ctrl+C 也不能Ctrl+Z。相同的命令,但没有 -Credential 部分工作正常。在我的本地机器上,即使使用-Credential,一切正常,所以这一定是某种配置问题。
我在寻找答案时偶然发现了this SO question,但this comment 对我没有多大帮助。
我尝试将执行策略设置为Bypass 和Unrestricted。我还尝试在本地组策略编辑器 > 计算机配置 > Windows 组件 > Windows PowerShell 中配置 Turn on Script Execution 以
允许所有脚本,但也没有任何运气。
【问题讨论】: