Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TFS Build: Run a Powershell script as administrator

I created a build definition for our nightly build server. After building the project (a windows service), I need to execute a Powershell script to install and start the service. So I added a build step to run the specific Powershell script. Then I installed a TFS Build Agent & Visual Studio at the (soon to be) nightly build server. After running the build script I got an 'exit code 5' which seems to be related to missing administratior permissions. If I start the script as admin on the server manually, it works fine. The user, which is used by the agent, already got admin permissions.

Is there a way to execute the powershell script on the build server with a build agent / build definition with admin permissions?

like image 228
TheWho Avatar asked Jul 19 '16 12:07

TheWho


People also ask

How do I run a PowerShell script as administrator?

Use PowerShell in Administrative Mode If you need to run a PowerShell script as an administrator, you will need to open PowerShell in administrative mode. To do so, find PowerShell on the Start menu, right click on the PowerShell icon, and then select More | Run as Administrator from the shortcut menu.


1 Answers

You just need to make sure your build service account (which can be a local account, a domain account, or Local Service in a workgroup) also got admin permission.

like image 127
PatrickLu-MSFT Avatar answered Sep 24 '22 08:09

PatrickLu-MSFT