0

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.

Paweł Hemperek
  • 1,130
  • 10
  • 21

1 Answers1

0

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.

Ranadip Dutta
  • 8,857
  • 3
  • 29
  • 45