-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazv-nets-subnets-ips.ps1
31 lines (29 loc) · 1.16 KB
/
azv-nets-subnets-ips.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
#Get-AzSubscription | Foreach-Object {
# $sub = Set-AzContext -SubscriptionId $_.SubscriptionId
# $vnets = Get-AzVirtualNetwork
#
# foreach ($vnet in $vnets) {
# [PSCustomObject]@{
# SubscriptionName = $sub.Subscription.Name
# VNetName = $vnet.Name
# VNetAddressSpaces = $vnet.AddressSpace.AddressPrefixes -join ','
# }
# }
#} | Export-Csv -Delimiter "," -Path "VNets.csv"
Get-AzSubscription | Foreach-Object {
$sub = Set-AzContext -SubscriptionId $_.SubscriptionId
$vnets = Get-AzVirtualNetwork
foreach ($vnet in $vnets) {
foreach($subnet in $vnet.Subnets)
{
[PSCustomObject]@{
SubscriptionName = $sub.Subscription.Name
VNetName = $vnet.Name
SubnetName = $subnet.Name
SubnetAddressPrefix = $subnet.AddressPrefix -join ','
UsedIPs = $subnet.IpConfigurations.Count
FreeIPs = [math]::Pow(2, (32 - $subnet.AddressPrefix.Split("/")[1])) - 5 - $subnet.IpConfigurations.Count # 5 IPs are used by Azure Networking
}
}
}
} | Export-Csv -Delimiter "," -Path "Subnets.csv"