Day 80 – Reducing Your Public Cloud Spend with PowerShell and Automation

Welcome to Day 80 of the “100 Days of DevOps with PowerShell”! For background on our goals in this series, see Announcing the “100 Days of DevOps with PowerShell” Series here at SCC. If this is the first time you are viewing an article of the series and you are new to DevOps and PowerShell Desired State Configuration (DSC), I encourage you to read through the previous installments, particularly Day 1.


In this installment, I am going to offer some direction on how you can leverage PowerShell in the public cloud (both MS Azure and Amazon EC2) to reduce your spending by minimizing your usage through PowerShell and other automation features in each platform. Specifically, we will talk briefly about the following two concepts:

  • Auto Scaling / Auto-Scale
  • Scheduled VM Start and Shutdown

With the rapid evolution of Azure and the difference in terms versus Amazon, finding the answer you seek for either platform could be challenging. However, in this article, I will point you to the resources that will get you to a solution in short order.

Auto-Scale / Auto Scaling

Auto-Scale (MS Azure) or Auto Scaling (Amazon) is great feature, more commonly for production scenarios, enabling you to scale out (and back in) based on workload demand for your important applications.

Azure Auto-Scale

Auto-scale in Azure is based on the CPU metric (utilization or queue depth), but behaves somewhat differently in Azure PaaS (non-persistent worker roles) and Azure IaaS (persistent VMs). Auto-scale for IaaS in Azure does not provision new VMs, it simply powers on (or off) existing instances you have already created, so VMs would have been created in the normal fashion (sometimes a VM is just a VM). On the other hand, the same feature in PaaS will spin up new workers.

The Azure Auto-Scale feature is configurable through the Azure Portal, but can also be configured via PowerShell, thought the operation will not appear trivial. For guidance, see an article titled, “Using the Windows Azure REST APIs with PowerShell” at, which will lead you to the “Update Auto-Scale Settings” article on MSDN at

For attritional reading on Azure Auto-Scale, here are two good articles:

There is a very helpful, brief explanation.

Autoscaling, Azure, WAP and System Center (part 1)

Auto Scaling in Amazon EC2

Auto scaling in Amazon EC2 is conceptually similar, but allows you to trigger automatic scale-out based on conditions other than CPU utilization and queue depth. Auto scaling allows you lets you define scaling policies driven by metrics collected by Amazon CloudWatch. There is a great explanation of Amazon Auto Scaling at

There is also some excellent sample PowerShell for auto scaling in Amazon on the StackOverflow website at

Scheduled VM Start and Shutdown

Scheduling VM startup and shutdown is a great approach in development, test and various lab scenarios to start VMs just before people get to work, and shut them down shortly after they leave.

In Azure

For a working example of scheduled start and stop of Azure VMs (IaaS), Anders Bengtsson has blogged a great working solution at “Scaling Azure VM with Azure Automation, with help of Azure SQL” at Anders uses PowerShell inside as an InlineScript{} in the Azure Automation runbook automation platform.

In Amazon

For scheduled start and stop of Amazon EC2 instances based on date and time, a nice working example comes from Arpioni, who uses custom Tags in Amazon EC2 to store schedule information to label VMs for when they should be started and stopped. His script uses the AWS PowerShell cmdlets Start-EC2Instance and Stop-EC2Instance. While his sample is based on day and hour, it could be easily tweaked to use full date, minutes, etc. To get a copy of his script, see “AWS – Auto schedule EC2 instance to start/stop” at


That’s all for this installment. I hope you are able to follow along as your schedule allows, building on your previous efforts to integrate the tips from this and other installments in the series into your enterprise DevOps strategy.

Previous Installments

To see the previous installments in this series, visit “100 Days of DevOps with PowerShell”.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.