Who likes to document? And who likes to keep theses documents updated?

Maybe not me, but sometimes documenting is necessary. So why not automate it?

Needed to document the structure of management groups and subscriptions, but they kept changing the whole time. So i found out that by write some CSV-document with definitions in comments I can actually write pwsh-code that generates this diagrams.

So I wrote this small one-function-module that can do just that

New-MgmGroupDiagram

A small Powershell module that only contains one function for creating diagrams from your Azure Managementgroups and Subscriptions hierarchy

How do I get set up?

  • Requires at least PowerShell 7 and Azure PS modules Az.Resources and Az.Accounts
  • Uses and requires default valid AzContext

How to use

First import the module

Import-Module -Name .\MgmGroupDiagram\MgmGroupDiagram.psm1

Then the simplest variant is just to run the command

New-MgmGroupDiagram  | Set-Clipboard

Then open diagrams.net and select Arrange/Insert/Advanced/CSV…

Clear the box with CSV and then paste the result from the command.

In my example this would result in a diagram that looks like this:

Showcasing an simple diagram

Let’s get some more details in our diagram

New-MgmGroupDiagram -IncludeManagementGroupRoles -ExpandSubscriptions -IncludeSubscriptionDetails  | Set-Clipboard

Then open diagrams.net and select Arrange/Insert/Advanced/CSV…

Clear the box with CSV and then paste the result from the command.

In my example this would result in a diagram that looks like this:

Showcasing an more detailed diagram

get-help New-MgmGroupDiagram -ShowWindow For full documentation of command run Get-Help New-MgmGroupDiagram -ShowWindow or see help here