Automating & Turning Off / Shutting Down Your Azure VMs

Category: Azure


This blog posts consists of 3 parts:

  1. Automating the shut down process of your Azure VMs (virtual machines) as a backup for when we forget to do it
  2. Setting up reminders for Azure billing thresholds when it goes beyond a certain spend amount or usage
  3. Understanding what “shut down” does and doesn’t mean in Azure

A quick history on Windows Azure pricing. Until a few months ago, Azure billed for any Virtual Machine (VM) that was in your account, even if it was not running. To much ballyhoo, legions of Microsoft techies applauded the change to not charge you for a VM when it is “shut down”. This is a great feature if you do not need to have your machines always up and running (i.e., demos, test, dev), but the reality is we are all human and I have met countless people that at some point have forgotten to turn them off (I am the poster child for this particular issue unfortunately). I hope this article will help you with some proactive steps you can take to avoid any unfortunate billing issues occurring.


1. Automating the Shut Down Process / Shutting Down of Your Azure VMs (Virtual Machines) as a Backup for When We Forget to Turn Them Off


2. Setting up Email / Text / Phone Reminders for Azure Billing Usage

If you can’t get something to automatically shut down your VMs, you could at least set up an Azure billing alert email (which could also forward to a text or phone call via a 3rd party service if desired). The good thing about this is that it is a reminder for the subscription’s total usage. This means if you have a lot of charges from things other than VMs such as bandwidth, storage or other items, the alert will still trigger. I have written a detailed blog post on how to do that here.


3. Understanding What “Shut Down” Does and Doesn’t Mean in Azure


Stop the VM from the management portal:


or through Azure PowerShell


Use the Azure Service Management API (I think this can only be done in C# but not sure as I am a bit of novice on this part), YES this is shut down:

ExecuteClientActionInOCS(null, CommandRuntime.ToString(), s => this.Channel.ShutdownRole(s, this.ServiceName, CurrentDeployment.Name, roleName, PostShutdownAction.StoppedDeallocated));




‘PostShutdownAction’ equal to “Stopped”. Running this code (I think in C#) will NOT shut down your VM from billing:

ExecuteClientActionInOCS(null, CommandRuntime.ToString(), s => this.Channel.ShutdownRole(s, this.ServiceName, CurrentDeployment.Name, roleName, PostShutdownAction.Stopped));


The Future…

The Azure Portal will soon include monitoring for VMs in their dashboard, however as of April 2014 it is not available yet. I am continuing to investigate new ways such as the preview of Azure Watch Scheduled Jobs to see if they may be other options available. If you figure out any yourself, please let me know and comment below!!!!

(Visited 16,419 times, 1 visits today)

Please rate this blog post!



  1. Question,

    when I shut down a VM using this script or simply the button in the Azure management portal I get a message stating that I will lose my VIP ip adress. How can I avoid this.
    I need the VIP IP adress for our demo of a archive appliance.

    Thanks in advance,


  2. Hi Toussaint,

    I had heard of some people setting up a small VM with the cheapest/lowest CPU/memory you can pick to leave on all the time to keep an IP as one trick. But more recently I thought that Azure made a change to allow 5 reserved IPs, however I have not looked into this myself. Check out this post at the 5:24 mark from Andrew Connell & Chris Johnson’s Microsoft Cloud Show podcast and see if it helps you:



  3. We just went through this confusion with Azure recently. We managed to claw back about $1,000 in related fees, but only because it so happened that it was not clear that a trial SharePoint VM was not “free” for the VM itself and the pricing docs were not clear. Without that “edge”, we’d have been out the dough. Totally agree that this is not yet well-managed, but happy to see that Azure is allowing for no-cost when it’s not running – that’s what’s bringing us over from other services (we run environments on a bunch of other providers).

  4. I am happy you were able to recover some of the money. I was not able to get a hold of anyone that had any authority to do anything, the only support contact I kept getting was an offshore 3rd party company that was handling the support for Azure at the time and handled it in the stereotypical offshore model.

  5. Hi Toussaint,

    I hope you are doing fine ! About the VM and it’s IP address ….. shouldn’t be so hard to only use the DNS name … create a CNAME in your own DNS and use that one ….

  6. Toussaint, you can now basically create a reservation, effectively giving you a static IP, even when the VM is shutdown (deallocated).

    #Checks to see if the IP is available. VM must be stopped (deallocated) for it to become available
    Test-AzureStaticVNetIP -VNetName YourNetworkNameHere -IPAddress you want)
    #Prepares the could service and VM named to be assigned an IP
    $staticVM = Get-AzureVM -ServiceName yourVM -Name YourVM
    #Assigns the IP listed to the service/VM named above
    Set-AzureStaticVNetIP -VM $staticVM -IPAddress | Update-AzureVM
    Get-AzureStaticVNetIP -VM $staticVM

  7. Hmm Well At least Try and Disconnect the VM from the same place where shutdown is close the VM And shut it down from the azure portal

  8. If your company is looking to systematize and monitor such cost-saving automation in their Azure environments, I would recommend checking out two blogs that show a more white-glove approach to how Azure VMs can be shutdown or scaled down on a schedule:

    Shut-down Azure VMs on a schedule:
    Scale-down Azure VMs on a schedule:

  9. Hey Matthew this is such a simple but straightforward post. A lot of people miss this detail. I also wanted to drop a not in the ring sort of similar to Igor. Here are some full-service approaches (without runbooks, powershell etc) to automating shutdown/resize based on time and/or VM utilization,:

Leave a Reply

Your email address will not be published.