Last active
March 28, 2018 02:57
-
-
Save giseongeom/39e9015c1e7e7365850b4f7101beca93 to your computer and use it in GitHub Desktop.
Display AzureRM VMName and (Primary) Private IP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $allNIC = Get-AzureRmNetworkInterface | |
| $allVM = get-azurermvm | Select-Object Name, ResourceGroupName, NetworkProfile | |
| $targetVM = $allVM | Where-Object { ($_.Name -like "*proxy*") -or ($_.Name -like "*api*") } | |
| # See https://blogs.technet.microsoft.com/rmilne/2016/11/15/how-to-get-azure-rm-vm-ip-addresses-using-powershell/ | |
| ForEach ($VMInfo in $targetVM) { | |
| $VMName = $VMInfo.Name | |
| $nic_id = $VMInfo.NetworkProfile.NetworkInterfaces[0].id | |
| $nic_info = $allNIC | Where-Object { $_.id -match $nic_id } | |
| $nic_private_ip = $nic_info.IpConfigurations.PrivateIpAddress | |
| Write-Output "$VMName, $nic_private_ip" | |
| "$VMName, $nic_private_ip" | Out-File C:\temp\iplist.txt -Encoding ascii -Append | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment