-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.ps1
More file actions
67 lines (56 loc) · 2.83 KB
/
Copy pathExample.ps1
File metadata and controls
67 lines (56 loc) · 2.83 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<#
.SYNOPSIS
End-to-end example: sign in to Azure, pick an Application Gateway,
export it with Dump-AzAppGWInfo, then launch the Flask visualizer.
.DESCRIPTION
1. Signs in to Azure (Connect-AzAccount) if there is no current context.
2. Lists the Application Gateways in the current subscription.
3. Exports the selected gateway with Dump-AzAppGWInfo -Force to the
data folder as <gateway-name>-appgw.json.
4. Runs .\start.ps1 to start the Flask app (http://localhost:5999).
5. Opens the app in the default browser once it responds.
.NOTES
Requires the Az.Accounts, Az.Network and Az.Resources modules:
Install-Module Az.Accounts, Az.Network, Az.Resources
#>
$Script:ErrorActionPreference = 'Break'
Set-Location -Path $PSScriptRoot
# ---- prerequisites ---------------------------------------------------------
foreach ($cmd in 'Connect-AzAccount', 'Get-AzContext', 'Get-AzApplicationGateway', 'Get-AzResource') {
if (-not (Get-Command $cmd -ErrorAction SilentlyContinue)) {
throw "Required command '$cmd' not found. Install the Az modules: Install-Module Az.Accounts, Az.Network, Az.Resources"
}
}
# Dot-source Dump-AzAppGWInfo.ps1 to load the Dump-AzAppGWInfo function.
. (Join-Path $PSScriptRoot 'Dump-AzAppGWInfo.ps1')
# ---- sign in if not already ------------------------------------------------
$ctx = Get-AzContext -ErrorAction SilentlyContinue
if (-not $ctx -or -not $ctx.Account) {
Write-Host "No Azure session found - signing in..."
Connect-AzAccount -ErrorAction Stop | Out-Null
$ctx = Get-AzContext
}
Write-Host ("Using subscription: {0} ({1})" -f $ctx.Subscription.Name, $ctx.Subscription.Id)
# ---- list the Application Gateways and pick one ----------------------------
Write-Host "Finding Application Gateways..."
$gateways = @(Get-AzApplicationGateway -ErrorAction Stop)
if ($gateways.Count -eq 0) {
throw "No Application Gateways found in subscription '$($ctx.Subscription.Name)'."
}
if ($gateways.Count -eq 1) {
$selected = $gateways[0]
Write-Host ("Found one Application Gateway: {0} (resource group: {1})" -f $selected.Name, $selected.ResourceGroupName)
}
else {
Write-Host "Select an Application Gateway to export:"
for ($i = 0; $i -lt $gateways.Count; $i++) {
Write-Host (" [{0}] {1} (resource group: {2}, location: {3})" -f $i, $gateways[$i].Name, $gateways[$i].ResourceGroupName, $gateways[$i].Location)
}
$choice = Read-Host "Enter number (0-$($gateways.Count - 1))"
if ($choice -notmatch '^\d+$' -or [int]$choice -ge $gateways.Count) { throw "Invalid selection." }
$selected = $gateways[[int]$choice]
}
# ---- export the selected gateway (overwrites any previous export) ----------
$selected | Dump-AzAppGWInfo -Force
# ---- start the Flask visualizer --------------------------------------------
& (Join-Path $PSScriptRoot 'start.ps1')