Is there a way to open and shutdown a VM out of Azure? Like on a third party app?

Arav Jivani 126 Reputation points
2021-07-20T11:29:46.523+00:00

Hello! Iam a new azure user and wanted to ask, is there a way to stop, restart or start an Azure VM outside of Azure itself?
So if I make another website for myself so I can start on stop my vm from there, is it possible to do? If it is how?

Thank you!

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,903 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Manu Philip 18,561 Reputation points MVP
    2021-07-20T12:24:26.77+00:00

    You may use Azure CLI to access VMs outside of the portal. Need a Service principal with the role of Virtual Machine Contributor.


  2. kobulloc-MSFT 26,326 Reputation points Microsoft Employee
    2021-07-20T15:06:54.133+00:00

    Managing VMs outside the portal
    Traditionally, you would use the portal, PowerShell, or the CLI to manage your VMs. Security and authorization is handled by the required sign in with each of these approaches and you can use default roles or custom roles to grant permission to control your VMs. The CLI can be run from Azure Cloud Shell and that would be a great option for managing your VMs from any location.

    Emanuele Bartolesi has a great guide for starting, stopping, and resetting a VM using basic CLI commands in a format that's easy for those new to Azure to follow along with:
    https://dev.to/expertsinside/start-restart-and-stop-azure-vm-from-azure-cli-41n9

    johnsterrett.com has a good explanation of how to create minimal permissions for a VM in a custom role if you wanted other users to be able to manage VMs:
    https://johnsterrett.com/2020/02/04/allow-users-to-start-stop-azure-vms/

    Other options for managing your VMs
    There are other options you can look into however you would want to be very careful how you implement this. Security vulnerabilities in your website means that your VMs could be run without your knowledge and that could result in significant additional costs.

    A webhook to a runbook could be used:
    https://learn.microsoft.com/en-us/azure/automation/automation-webhooks

    You can also look at the REST API:
    https://learn.microsoft.com/en-us/rest/api/compute/virtual-machines

    Additional Reading:

    0 comments No comments

  3. Manu Philip 18,561 Reputation points MVP
    2021-07-20T15:46:55.74+00:00

    Here are the simple steps to enable you to start, stop, connect Windows machines through RDP using PowerShell and Azure CLI You need to install AZ one time which enables you to connect the VM through PowerShell Install AZ from the link :installazurecliwindows

    After the installation is completed, you may follow the steps each time when you wanted to start, connect, stop the vm 1. Start the VM: Run the following command from PowerShell in administrator mode

     az vm start -g "Your resource group name" -n "Your VM name"
    
    1. Connect the VM: Run the following command from PowerShell in administrator mode Get-AzRemoteDesktopFile -ResourceGroupName "Your resource group name" -Name "Your VM name" -Launch
    2. Stop the VM: Run the following command from PowerShell in administrator mode az vm stop -g "Your resource group name" -n "Your VM name"
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.