-
Notifications
You must be signed in to change notification settings - Fork 0
/
createRGTopology.ps1
52 lines (41 loc) · 1.61 KB
/
createRGTopology.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
52
<#
---------------------------------------------------------------------------------
Description: Create a visualzied graphical image for resources in a Azure
Resource Group
Author: Samir Budhdeo
Created: 2023-02-24
---------------------------------------------------------------------------------
Required Modules
- Install-Module -Name Az
GraphViz is also required
---------------------------------------------------------------------------------
Runtime Varibles for out files, email and sendmail prep
---------------------------------------------------------------------------------
#>
# Connect to your Azure account
Connect-AzAccount
#Set the Azure subscription
Set-AzContext -SubscriptionId <your id>
# Set the resource group name
$resourceGroupName = "yourRGname"
# Get the servers in the resource group
$servers = Get-AzSqlServer -ResourceGroupName $resourceGroupName
# Create the graphviz script
$graphvizScript = "graph {"
# Loop through each server and add it to the script
foreach ($server in $servers) {
$serverName = $server.ServerName
$graphvizScript += "`"$serverName`";"
# Get the databases for the server
$databases = Get-AzSqlDatabase -ResourceGroupName $resourceGroupName -ServerName $serverName
# Loop through each database and add it to the script
foreach ($database in $databases) {
$databaseName = $database.DatabaseName
$graphvizScript += "`"$databaseName`" -> `"$serverName`";"
}
}
$graphvizScript += "}"
# Convert the graphviz script to a PNG image
Invoke-Expression "dot -Tpng -ograph.png" $graphvizScript
# Open the image
Invoke-Item "graph.png"