0
votes

Have an on-prem agent that is used when running a release pipeline. On of my tasks is a powershell script that needs to stop a windows service, hence it needs admin rights. The agent runs under an account that has admin rights so that has me wondering, how does one run a powershell script as an admin on an agent of a deployment group?

You have to elevate its permissions somehow, the same way as if you run a powershell command "run as administrator".

2

2 Answers

1
votes

AzureAdmin will work perfectly for you. We got around the same thing not being able to use elevated Powershell commands by creating a light .Netcore Worker service with http request capability. Just make sure you install the service with admin privileges and You can send a Invoke-RestMethod command from a regular Powershell YML task and it will trigger your custom logic on the other end of the ASP controller. We use it to remove Appx packages before re-installing for our Unit tests. The repo is located at, Here Customize it however you'd like.

0
votes

How does one run a powershell script as an admin on an agent of a deployment group?

It is not supported simply elevating permissions to run PowerShell as an administrator.

You can use a built-in task called "PowerShell on target machines" instead, which need you to provide some machine details and admin credentials:

  1. a comma separated list of machine IP addresses or FQDNs along with ports. Port is defaulted based on the selected protocol. Eg: dbserver.fabrikam.com,dbserver_int.fabrikam.com:5986,192.168.12.34:5986

  2. The administrator's username and password.