Home > Software design >  Azure devops , Powershell script , login to VM agent
Azure devops , Powershell script , login to VM agent

Time:03-28

I want to stop service in VM Agent with powershell script how can I login to the vm with the powershell script And run a Stop-Service command on agent after login.

I know there is a built-in stop-service task in azure devops with connecting to vm agent but I need to do more action in the meantime.

I want to stop service in VM Agent with powershell script how can I login to the vm with the powershell script And run a Stop-Service command on agent after login.

I know there is a built-in stop-service task in azure devops with connecting to vm agent but I need to do more action in the meantime.

CodePudding user response:

You can use Invoke-AZVMRunCommand to execute a command in a remote VM. https://docs.microsoft.com/en-us/powershell/module/az.compute/invoke-azvmruncommand?view=azps-7.3.2#examples

https://4sysops.com/archives/running-powershell-scripts-remotely-on-azure-virtual-machines/

CodePudding user response:

There are a variety of ways which you can run commands on another host using powershell. Which one you use depends on your environment.

Suggest reading this documentation to see which one fits best.

https://docs.microsoft.com/en-us/powershell/scripting/learn/remoting/running-remote-commands?view=powershell-7.2

https://learn-powershell.net/2012/01/15/startingstopping-and-restarting-remote-services-with-powershell/

  • Related