question

AravJivani-7283 avatar image
0 Votes"
AravJivani-7283 asked ManuPhilip edited

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

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ManuPhilip avatar image
0 Votes"
ManuPhilip answered AravJivani-7283 commented

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

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello! Thank you for your response. Sorry, but iam new to Azure, can you maybe give me more clear ways on how to do it?

0 Votes 0 ·
kobulloc-MSFT avatar image
0 Votes"
kobulloc-MSFT answered kobulloc-MSFT edited

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://docs.microsoft.com/en-us/azure/automation/automation-webhooks

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


Additional Reading:

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ManuPhilip avatar image
0 Votes"
ManuPhilip answered ManuPhilip edited

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"

















5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.