Master Azure VM Management with PowerShell and Custom Script Extensions

Managing Azure Virtual Machines (VMs) individually can be slow, repetitive, and inefficient—especially at scale. In this post, we’ll explore how to leverage PowerShell and Azure Custom Script Extensions to automate updates, configurations, and software installations across one or hundreds of Azure VMs in minutes.

Why Automation Matters for Azure VM Management

In enterprise environments, efficiency is everything. Manually connecting to each VM for updates or configuration changes wastes valuable time and increases the risk of inconsistencies. By using Custom Script Extensions with PowerShell, you can apply changes across your environment simultaneously—reducing errors and ensuring consistent results.

What Are Custom Script Extensions?

Azure Custom Script Extensions allow you to run scripts directly on Azure VMs without logging into each one. This can include tasks such as installing applications, applying configuration changes, or updating system settings. Scripts can be hosted publicly, such as on GitHub, or stored securely in Azure Blob Storage.

PowerShell Commands to Know

There are two key PowerShell commands for working with Custom Script Extensions:

  • Set-AzVMExtension: Works with multiple extension types, including Custom Script Extensions.
  • Set-AzVMCustomScriptExtension: Purpose-built for deploying Custom Script Extensions.

For most use cases, Set-AzVMCustomScriptExtension is the better option as it’s designed specifically for this task.

Demo Overview

In the demonstration, we cover three key scenarios:

  1. Deploying a script hosted publicly on GitHub to a single VM.
  2. Deploying a script stored in an Azure Blob Storage account for enhanced security.
  3. Running scripts against multiple VMs using loops and splatting in PowerShell.

We also review how to check the status of your deployments, troubleshoot with logs, and remove Custom Script Extensions when they’re no longer needed.

The code used for the demonstration can be found in the links below.

Example Use Cases

Some of the tasks demonstrated in the video include:

  • Changing registry values.
  • Setting the server time zone.
  • Downloading and installing BGInfo.
  • Installing Google Chrome with Chocolatey.

These examples are intended to show what’s possible—you can adapt them to fit your own automation needs.

Best Practices

When working with Custom Script Extensions, keep these best practices in mind:

– Avoid hardcoding sensitive information like storage account keys in scripts.
– Use Azure Key Vault to securely retrieve secrets at runtime.
– Test scripts in a lab before deploying to production.
– Always review logs for troubleshooting and validation.

Conclusion

PowerShell Custom Script Extensions are a powerful way to manage Azure VMs at scale. By automating repetitive tasks, you can save time, improve consistency, and reduce the risk of human error. Whether you’re managing a small lab or a large enterprise environment, these techniques can help you take full control of your Azure infrastructure.

Links

A Beginner’s Guide to the AZ-900
https://www.udemy.com/course/beginners-guide-az-900/?referralCode=C74C266B74E837F86969

Zero to Hero with Azure Virtual Desktop
https://www.udemy.com/course/zero-to-hero-with-windows-virtual-desktop/?referralCode=B2FE49E6FCEE7A7EA8D4

Hybrid Identity with Windows AD and Azure AD
https://www.udemy.com/course/hybrid-identity-and-azure-active-directory/?referralCode=7F62C4C6FD05C73ACCC3

Windows 365 Enterprise and Intune Management
https://www.udemy.com/course/windows-365-enterprise-and-intune-management/?referralCode=4A1ED105341D0AA20D2E

Link to the code on GitHub
https://github.com/tsrob50/CiraltosTools

Previous Custom Script Extension Video
Master Azure VM Automation with Custom Script Extensions | Full Tutorial & Demo Video

Leave a Comment

Your email address will not be published. Required fields are marked *

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

Click Here!
Scroll to Top