Can I use a runbook to start a VM and run commands in the VM?

np 11 Reputation points
2021-03-15T01:30:00.41+00:00

I would like to receive a HTTP post request from a web application, and then run a command on the VM (like I would when I SSH into the VM) and return the output. Is this possible using a runbook or any other Azure services?

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,142 questions
0 comments No comments
{count} vote

2 answers

Sort by: Most helpful
  1. Weily 86 Reputation points
    2021-03-15T02:32:23.007+00:00
    2 people found this answer helpful.
    0 comments No comments

  2. tbgangav-MSFT 10,386 Reputation points
    2021-03-15T05:20:02.813+00:00

    Hi @np ,

    If it's Azure VM then you could start it using Az PS Cmdlet Start-AzVM and then you can have commands stored as script in a storage blob and run those commands in the VM using Az PS cmdlet Invoke-AzVMRunCommand. For more information w.r.t it or for illustration, please refer this thread.

    Let me know if you have any further queries around it. Also, If you have queries on how to implement receiving a HTTP post request from a web application, etc. I believe you would have to use curl if it has to be from the script that is stored in storage blob / use Invoke-RestMethod if it has to be from runbook itself. To provide exact implementation assistance, please provide more context like your exact use case / scenario / flow that's intended.

    2 people found this answer helpful.