Systems Management
Minimize Azure AVD Costs with PowerShell and Automation
Topics: Systems Management
Traditional VDI solutions like VMware Horizon and Citrix Virtual Apps and Desktops are often expensive, and recent changes in licensing and forced DaaS migration make them even more costly. It’s no wonder that more organizations are exploring AVD (Azure Virtual Desktop) as an alternative. I see this trend emerging more and more in the Netherlands when I speak to our partners and customers
Another reason some organizations consider AVD is the complexity of certain custom applications or legacy software, which often leads to the continued use of a VDI solution. Frequently, these factors lead organizations to revisit AVD as a viable option. However, the cost structure is entirely different from running everything in an on-premises data center.
If you’re expecting another deep dive into Application Workspace today—surprise!—this post is going in a completely different direction. I’ll break down the strategies I’ve discovered for keeping AVD costs manageable without sacrificing the powerful experience.
This brings us to a key challenge: How can we keep AVD costs manageable without sacrificing performance? There are plenty of articles and forums that discuss specific use cases, pros, and cons, so I won’t delve into that here. Instead, I’ll focus on the small steps you can take to reduce costs in an AVD environment. For instance, I run a small AVD environment in my Azure demo tenant, utilizing a Microsoft MPN subscription. This gives me a limited monthly budget to spend on my environment. It’s a situation that many IT admins or consultants can relate to, right? We often find ourselves in situations where every little saving can make a significant difference, whether it’s optimizing resources or finding more efficient ways to manage systems.
Got your attention? Alright, let’s dig in.
Top Strategies to Minimize Azure AVD Costs
Running virtual machines (VMs) in Azure involves various costs, including those for compute, storage, network, and other components. While compute costs stop once VMs are deallocated, Microsoft continues to charge for storage, as the virtual disks still occupy underlying storage resources.
For those using AVD, your session hosts probably don’t need to run 24/7, whether you’re managing a test environment or even a production one. This means you can start and stop VMs as needed, reducing compute costs. However, storage costs persist even when VMs are deallocated. Since storage performance is irrelevant when a VM is deallocated (stopped), why not switch the disk type to Standard HDD (the cheapest option) after stopping the VMs and revert to Premium SSD (higher performance) before starting them again?
This scenario is absolutely possible, and you can automate the process using Azure Automation and PowerShell scripts. These scripts can help you with the following:
- Automatically shut down and start up VMs based on a schedule.
- Swap the disk type to Standard HDD after stopping VMs and revert to Premium SSD before starting them.
By implementing this simple solution, you can significantly optimize your Azure VM costs without compromising performance when it matters most.
Calculating the Savings: A Cost Comparison of Azure VMs
In our scenario, we are using a VM Instance D2as v5 (2 vCPUs, 8 GB RAM) with a disk size of 128 GB. All these calculations were done with the Azure Pricing calculator.
Monthly Cost Calculation for a VM
Let’s compare the monthly costs of running the above-mentioned VM instance continuously versus a VM that starts at 7:00 AM and shuts down automatically at 7:00 PM. The calculation is as follows:
- 12 hours per day x 22 days (working week) = 264 hours per month
Note: On average, there are about 21 to 22 working days in a month. This is based on the typical 5-day work week (Monday to Friday) and considering that most months have around 4 weeks and a few extra days.
Since we have the Azure Hybrid Benefit, we can use our existing Windows 11 licenses to run virtual machines on Azure without incurring additional licensing costs. We will also use the Pay-as-You-Go subscription for our example.
- Monthly cost $71.39
- Optimized cost $25.82 (240 hours)
Managed Disk 128 GB Standard HDD vs. Premium SSD
- Standard HDD $5.53 (per month)
- S10: 128 GB
- Premium SSD LRS $20.39 (per month)
- P10: 128 GB
Do the math. I hope this comparison will help you understand the potential savings.
Automate Cost Savings with PowerShell Scripts
You’re in the right place! I’ve already done the heavy lifting by creating some powerful PowerShell scripts that you can start using right away.
Feel free to hop over to my GitHub to check them out and grab the scripts directly.
Implementing the Solution: Step-by-Step Guide
Managing virtual machines (VMs) in AVD often involves tasks like shutting them down at specific times. Fortunately, this process can be automated directly through the GUI. However, to achieve this efficiently, we will use PowerShell scripts in combination with runbooks scheduled in Azure Automation. This approach is an excellent way to automate tasks at specific times without any manual intervention. I’ve added an extra bonus by making my automation process even more secure by integrating Azure Key Vault into my PowerShell scripts used in Automation Runbooks. Now, sensitive values like subscription or resource group names aren’t hard-coded anymore. Instead, secrets are securely managed, and thanks to Azure’s access control, only the Automation Account running the scripts can access the secrets it requires. This boosts security significantly!
To get everything working smoothly and achieving the results we strive for, here are the steps you need to follow:
Create an Azure Key Vault
- Managed identity (in our case Automation Account) used in the PowerShell scripts needs to have the Key Vault Secrets User role on the resource to be able to access the secret within Azure Key Vault.
- Create Key Vault secrets for the resource group name and subscription name to use in the PowerShell script within Azure Automation Runbooks.
Create an Azure Automation Account
- The managed identity (in our case, the Automation Account) used in the PowerShell scripts needs to have the Virtual Machine Contributor role on the resource groups where the VMs to be managed are located.
- Create the Runbook and use the PowerShell scripts I wrote.
- Create the schedules for the Runbooks.
- Link the Schedules to the Runbook.
- Test and Monitor (Jobs) the Runbooks.
Results: Achieving Significant Azure AVD Cost Reductions
Conclusion: Optimize Azure AVD Costs with Automation
Looking to slash your Azure AVD costs? By automating VM management with PowerShell and Azure Automation, you can optimize performance while keeping expenses in check. Integrating Azure Key Vault with Automation Runbooks removes the need to hard-code sensitive values, boosts security, streamlines updates, and provides seamless, secure access.