-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlistUnsuedApplicationGateways.ps1
More file actions
40 lines (31 loc) · 1.21 KB
/
listUnsuedApplicationGateways.ps1
File metadata and controls
40 lines (31 loc) · 1.21 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
# Login to Azure
Connect-AzAccount
# Get all Application Gateways
$appGateways = Get-AzApplicationGateway
# Initialize an array to store unused Application Gateways
$unusedAppGateways = @()
# Check each Application Gateway for associated backend pools
foreach ($appGateway in $appGateways) {
if ($appGateway.BackendAddressPools.Count -eq 0) {
$unusedAppGateways += $appGateway
}
}
# Display the unused Application Gateways
$unusedAppGateways | ForEach-Object {
Write-Output "Application Gateway: $($_.Name) - Resource Group: $($_.ResourceGroupName)"
}
# Get all VNET Gateways
$vnetGateways = Get-AzVirtualNetworkGateway
# Initialize an array to store unused VNET Gateways
$unusedVnetGateways = @()
# Check each VNET Gateway for connections
foreach ($vnetGateway in $vnetGateways) {
$connections = Get-AzVirtualNetworkGatewayConnection | Where-Object { $_.VirtualNetworkGateway1.Id -eq $vnetGateway.Id -or $_.VirtualNetworkGateway2.Id -eq $vnetGateway.Id }
if ($connections.Count -eq 0) {
$unusedVnetGateways += $vnetGateway
}
}
# Display the unused VNET Gateways
$unusedVnetGateways | ForEach-Object {
Write-Output "VNET Gateway: $($_.Name) - Resource Group: $($_.ResourceGroupName)"
}