I wrote a powershell script for a custom TFS task (Build and Release Task). Now I need to execute some command with specific credentials. For this I create the following statement:
Start-Process powershell -Credential $mycred -Wait -ArgumentList "-file $taskDir\task.ps1" -RedirectStandardOutput C:\Temp\taskOutput.log
If I execute the command in the powershell, everything works correctly. But as soon as the command will be executed from the TFS service, it doesn't work. If I remove the -Credential $mycred
parameter, the command also works in context of the TFS execution.
I guess that the problem is, that with the -Credential $mycred
a new window was opened. And so it doesn't work within the TFS execution.
Anyone knows a better solution to execute a powershell script with specific credential?
Thanks!!
UPDDATE 1:
For better understanding I upload the full custom task here