Save money in Azure by shutting down your VMs

Unless you have been living under a rock for the last few years you are probably well aware that Cloud hosted servers or (infrastructure as a service as it is called) is currently all the rage. It does have some great advantages, like not having to maintain any hardware and the ability to increase/decrease resources at the push of a button to name two of the big ones. However, it can be bloody expensive if you don’t manage it correctly.

One way to help lower the cost is to turn off non essential cloud based virtual machines when you aren’t using them. In my case I use my personal Azure subscription as a dev/test environment so I only need the machines powered on when I want to use them.

The easiest way to start up and shutdown Azure based VM’s on a specific schedule is to create an Azure Runbook. Although I don’t have a specific schedule so instead of using a Runbook I simply run a PowerShell script from my local workstation when I want to power the virtual machines on and run another one when I am finished and I want the machines shut down.

Below are both scripts, all you need to do is fill in your Azure subscription into the $AzureSub variable and when you run the script it will ask for your Azure login details. Other than that there isn’t much too it. It will get a list of all your virtual machines and shut them down/start them up one at a time.

Start VMs

Stop VMs

You can get a copy of the scripts here but keep in mind these scripts don’t factor in a start/stop order so if you run a Windows domain (as an example) these scripts are not very helpful. These are good if you have a few test/dev machines you can shutdown all at the same time.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s