forked from fabferri/az-pattern
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-IPs.ps1
31 lines (26 loc) · 1.16 KB
/
get-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
# Getting all the IPs of the VMs
#
$subscriptionName = "AzureDemo3"
$rgName = "ipv6-1"
$vmArray = @("h11", "h11", "h2", "nva", "s1", "s2")
foreach ($vmName in $vmarray) {
$VM = Get-AzVM -ResourceGroupName $rgName -Name $vmName
$NIC = $VM.NetworkProfile.NetworkInterfaces[0].Id -replace '.*\/'
$NI = Get-AzNetworkInterface -Name $NIC -ResourceGroupName $rgName
$NIIC = Get-AzNetworkInterfaceIpConfig -NetworkInterface $NI
write-host "----------------------"
foreach ($a in $NIIC) {
write-host -ForegroundColor Cyan "$vmName-private IP address: " $a.PrivateIpAddress
}
try {
$namePubv4 = $vmName + "-pubIP"
$namePubv6 = $vmName + "-pubIP6"
$vm_pubv4 = (Get-AzPublicIpAddress -Name $namePubv4 -ResourceGroupName $rgName -ErrorAction Ignore).IpAddress
$vm_pubv6 = (Get-AzPublicIpAddress -Name $namePubv6 -ResourceGroupName $rgName -ErrorAction Ignore).IpAddress
write-host "$vmName-public IPv4 : "$vm_pubv4 -ForegroundColor Yellow
write-host "$vmName-public IPv6 : "$vm_pubv6 -ForegroundColor Yellow
}
catch {
write-host "$vmName-public IPv6 : -"
}
}