src/private/Get-TenantDiagrams.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# https://www.reddit.com/r/PowerShell/comments/mmxq6a/powershell_module_to_visualize_and_document_azure/gtwb6uf?utm_source=share&utm_medium=web2x&context=3
function Get-TenantDiagrams {

    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)][ValidateSet('light', 'dark', 'neon')]$theme,
        [Parameter(Mandatory = $true)][ValidateScript( { Test-Path -Path $_ -IsValid })][string] $OutputFilePath,
        [Parameter(Mandatory = $false)][ValidateSet(1, 2, 3)][int] $LabelVerbosity = 1,
        [Parameter(Mandatory = $false)][ValidateSet(1, 2, 3)][int] $CategoryDepth = 1,
        [Parameter(Mandatory = $false)][ValidateSet('png', 'svg')][string] $OutputFormat = 'png',
        [Parameter(Mandatory = $false)][ValidateSet('left-to-right', 'top-to-bottom')][string] $Direction = 'left-to-right'
    )

    $script:dateis = Get-Date -Format MM-dd-yyyy

    if ($OutputFormat -eq 'svg') {
        $script:extension = '.svg'
    }
    else {
        $script:extension = '.png'
    }


    $Subscriptions = Get-AzSubscription

    foreach ($sub in $Subscriptions) {
        Get-AzSubscription -SubscriptionName $sub.Name | Set-AzContext
        $script:name = $sub.name
        New-Item -Path $OutputFilePath\$dateis\$name -ItemType Directory | Out-Null
        $AZResourcegroups = Get-AzResourceGroup

        foreach ($RGName in $AZResourcegroups) {

            $RG = $RGName.resourcegroupname
            $filename = $RG + $extension

            $Params = @{
                ResourceGroup  = $RG
                OutputFilePath = "$OutputFilePath\$dateis\$name\$filename"
                Theme          = $Theme
                OutputFormat   = $OutputFormat
                CategoryDepth  = $CategoryDepth
                Direction      = $Direction
                LabelVerbosity = $LabelVerbosity
            }

            Get-AzViz @params

        }
    }
}