Generate Azure Resource Diagrams using PowerShell

We’ve all been there. You’ve been working on implementing a solution in Azure and you’ve finally finished building it. It’s all working, and it is time to hand it over to someone else to support. The adage of a picture is worth a thousand words has always stuck in my head, and I always start with a diagram. They can be very time consuming to create and even more so maintain. Recently I saw this tweet from Prateek Singh on a module he’d just published for generating Azure Resource Diagrams using PowerShell. I investigated AzViz and it does just that. Point it at Azure Resource Group(s) and it will generate a diagram of the resources and their relationships with each other. And all using my favorite language PowerShell.

Installing and Importing the AzViz PowerShell Module

The AzViz module can be installed from the PowerShell Gallery with Windows PowerShell 5.1+ or PowerShell 7+. Likewise, so can the Az (Azure PowerShell) PowerShell Module Az which is required to access your Azure Tenant.

install-module -name AzViz
install-module -name Az

The AzViz PowerShell Module also requires GraphViz. That can be downloaded from GraphViz here. Then install it on the computer you will be using AzViz on.

With GraphViz, AzViz and Az installed, import the AzViz module and use the Connect-AzAccount cmdlet from Az to authenticate to your Azure Tenant.

Import-Module AzViz
Connect-AzAccount -TenantId <yourAADTenantID>

Using AzViz

Using the module is very straightforward. Provide it with the Resource Group(s) you want to Generate Azure Resources Diagrams using PowerShell for and specify an output format (currently SVG or PNG). Colorization is optional using the -theme (light, dark or neon) option. The time to generate the Azure resource diagrams using PowerShell will depend on the number of resources in the resource group and their relationships.

Export-AzViz -ResourceGroup yourResourceGroup -Theme light -OutputFormat svg -show

Generate Azure Resource Diagrams using PowerShell and AzViz

Exported Diagram

Using the -show switch will open the diagram in your browser or default application for PNG/SVG files. By default without using the -OutputFilePath option to provide a path and filename the generated diagram will named output.svg (or output.png) and placed in the %localappdata%\temp directory (on Windows). For more depth of resource categories explore the -CategoryDepth option. And for more verbose labels explore the -LabelVerbosity option.

Generate Azure Resource Diagrams using PowerShell IaaS example output

Editing Exported Diagrams in Visio

When I first looked at this a couple of weeks back, my first thought was this is awesome. My second was, how do I edit the generated diagram so I can add additional details or change some formatting. I even submitted a feature request for that.
Since then I have realized that Microsoft Visio has the ability to handle SVG files and treat elements in a generated diagram as discreet entities. Therefore, they can be rearranged and the diagram updated.

Generate Azure Resource Diagrams using PowerShell and editing with Visio

Summary

Using AzViz allows you to quickly generate diagrams for Azure Resources. Quickly being able to generate accurate diagrams for documentation means we can get onto building the next interesting thing. Thanks Prateek.