Search code examples
azurepowershellazure-devopsazure-rm-templateazure-devops-self-hosted-agent

create azure devops windows self hosted agent remotely


Need to create azure devops windows self-hosted agents programmatically (Need to install Remotely for the existing VM).

I have PS script and it is working well if i run it (as admin) inside the virtual machine and agent is getting installed successfully. But i want to create this agent for the existing VM without logging in (Remotely i need to install the agent), because i will need to just add the ARM template in Azure devops pipeline and that should create the Agent for the existing VM.

As this needs to be installed remotely and securely, i shouldn't use custom script due to some restrictions.. It would be really great if we can achieve this installation remotely without custom script and using any other automated way.

Any information will be helpful, thanks.


Solution

  • I have found out a way using Run-Command. This is another helpful option to run the PS scripts remotely on a Virtual machine. In addition, this executes the script with elevated permissions which is really helpful in many scenarios.

    Source: https://learn.microsoft.com/en-us/azure/virtual-machines/windows/run-command#powershell

    This can be performed using via Portal, Powershell and CLI as well.