Microsoft Azure

How to Force an Azure VM Shutdown

In this easy Ask the Admin, I’ll show you how to force an Azure virtual machine to shut down.

Azure VMs are generally reliable, but there can be occasions when they get stuck during the start process and cannot be further controlled using the web-based management portal. In this article, I’ll show you how to use PowerShell to resolve this problem so that you can have another, hopefully successful attempt, at starting your virtual machine.

A Common Reason to Force an Azure VM to Shut Down

There are different reasons why you might want to force an Azure VM to shut down, but one of the most common is if a VM hangs when starting. Before you run the commands below, you will need to have Microsoft Azure PowerShell installed on your management PC, and make a secure connection to your Azure subscription. For more information on managing Azure using PowerShell, see Setup Windows Azure PowerShell Management on the Petri IT Knowledgebase.

Once you’ve got Microsoft Azure PowerShell installed, and a publish settings file downloaded and imported for your Azure subscription, open a PowerShell prompt and select the Azure subscription that you want to use in the current session:

Sponsored Content

Maximize Value from Microsoft Defender

In this ebook, you’ll learn why Red Canary’s platform and expertise bring you the highest possible value from your Microsoft Defender for Endpoint investment, deployment, or migration.

​Select-AzureSubscription –SubscriptionName Pay-As-You-Go

If you’re not sure what Azure subscriptions have been installed on the local management PC, run the command below and look for the SubscriptionName field in the results:


You can confirm the subscription set in the current PowerShell session using Get-AzureSubscription:

​Get-AzureSubscription –Current

Stop an Azure Virtual Machine

Now that PowerShell is configured and the Azure subscription set in the current session, let’s look at forcing a shutdown. Using the Stop-AzureVM cmdlet as shown below, specify the VM’s name, contososrv1 in this example, and the related cloud service, which is also contososrv1:

​Stop-AzureVM –Name contososrv1 –ServiceName contososrv1 -Force

If you’re not sure of the cloud service name, use Get-AzureVM to list all the VMs in the subscription and return the cloud service names. You can pipe the results of the Get-AzureVM cmdlet to Where-Object, which will return information just about a specific virtual machine if you have a lot of VMs in the subscription:

Forcing an Azure VM to shut down using PowerShell (Image Credit: Russell Smith)
Forcing an Azure VM to shut down using PowerShell (Image Credit: Russell Smith)
​Get-AzureVM | where { $_.Name –eq 'contososrv1' }

Alternatively, you can pipe the results of the above command line straight to the Stop-AzureVM cmdlet, without manually typing the cloud service name:

​Get-AzureVM | where { $_.Name –eq 'contososrv1' } | Stop-AzureVM -Force

You’ll notice in the figure that the VM’s status is ReadyRole, which means that it has successfully booted. If your VM is hung during startup, the status might be RoleStateUnknown.

Once the VM has actually shut down the status will be StopDeallocated, at which point you can either return to the web-based management portal and attempt to start it again, or use PowerShell as shown here:

​Get-AzureVM | where { $_.Name –eq 'contososrv1' } | Start-AzureVM

For more information on managing Azure VMs using PowerShell, see Stop or Start VMs in an Windows Azure Subscription Using PowerShell Loop and Stop Microsoft Azure Virtual Machines in Parallel using PowerShell on the Petri IT Knowledgebase.

Related Topics:


Don't have a login but want to join the conversation? Sign up for a Petri Account

Comments (0)

Leave a Reply

IT consultant, Contributing Editor @PetriFeed, and trainer @Pluralsight. All about Microsoft, Office 365, Azure, and Windows Server.
External Sharing and Guest User Access in Microsoft 365 and Teams

This eBook will dive into policy considerations you need to make when creating and managing guest user access to your Teams network, as well as the different layers of guest access and the common challenges that accompany a more complicated Microsoft 365 infrastructure.

You will learn:

  • Who should be allowed to be invited as a guest?
  • What type of guests should be able to access files in SharePoint and OneDrive?
  • How should guests be offboarded?
  • How should you determine who has access to sensitive information in your environment?

Sponsored by: