简体   繁体   中英

Start-Process hangs when used with -Credential

During my continuous delivery pipeline I would like to run Powershell script which starts my .NET Core application used to update database. Problem is user used TFS agent has no permissions to connect to MSSQL server. That's why I would like to run this process as different user. What I'm doing right now is

$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

Running this script causes Powershell window to freeze. I can't do Ctrl+C nor Ctrl+Z . The same command, but without -Credential part works fine. On my local machine everything works fine even with -Credential so this has to be some kind of configuration issue.

I was looking for an answer and stumbled upon this SO question , but this comment doesn't help me much.

I tried to set up execution policy to Bypass and Unrestricted . I also tried to configure Turn on Script Execution in Local Group Policy Editor > Computer Configuration > Windows Components > Windows PowerShell to Allow all scripts, but also without any luck.

Try this:

Start-Process -FilePath 'dotnet' -ArgumentList 'MyApp.dll' -NoNewWindow -Credential $credential -PassThru| Wait-Process -Timeout 5 -ErrorAction Stop 

Instead of directly giving -Wait .

PS: You can put some try catch also which will help you out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM