0

As part of our TFS build definitions we included a custom PowerShell as a last build step to identify the left over process from the build and kill them.

Inside the script we added below PowerShell command to list all the Dlls and the process associated with it. after that we loop through the output to get the process details and kill it.

$dllsByProc = Invoke-Expression  -Command "E:\BuildSetup\SysinternalsSuite\Listdlls.exe -d E:\Dev\D\47\s"
Write-Host $dllsByProc

This all works fine when i run the script on a PowerShell window in admin mode but doesn't work when i add this script as a build step.

This confirms me that i need to run the ListDlls.exe gives the complete result only when run in admin mode.

My questions is how i can run a PowerShell command in admin mode from TFS build step

TIA

Naresh
  • 35
  • 4
  • See if this helps: https://stackoverflow.com/q/35578468/6610379 – Phil Brubaker Jan 12 '18 at 17:03
  • @Phil Brubaker. Thanks for the Prompt reply. Service account used by the build agent is already having admin access.The stark difference between the results is when i used two Powershell windows. The normal Powershell ISE doesn't give the results but Powershell ISE launched as admin gives results as charm – Naresh Jan 12 '18 at 17:14
  • Did you run the script on the build agent machine when you mentioned "all works fine when i run the script on a PowerShell window in admin mode"? If you run the script in other mode than admin, how's the result? Could you share your build log? – Cece Dong - MSFT Jan 15 '18 at 09:02
  • After you adding the build service account in the admin group, did you try to restart the machine? – Cece Dong - MSFT Jan 24 '18 at 09:19
  • build service account is added to admin group long back. We have a scheduled reboot for the machines. So i dont think this should be a reason – Naresh Feb 01 '18 at 15:01

1 Answers1

0

Thanks all for the response.

I can't say this as a solution but a workaround. One interesting thing i noticed is that when we execute a power shell script inline of a build step,then the script is getting executed as intended (i,e the script is getting executed as in admin mode.

So i condensed my script to fit in as inline script and obtained the desired result

Naresh
  • 35
  • 4