Skip to content

Instantly share code, notes, and snippets.

@giseongeom
Last active March 28, 2018 02:57
Show Gist options
  • Select an option

  • Save giseongeom/39e9015c1e7e7365850b4f7101beca93 to your computer and use it in GitHub Desktop.

Select an option

Save giseongeom/39e9015c1e7e7365850b4f7101beca93 to your computer and use it in GitHub Desktop.
Display AzureRM VMName and (Primary) Private IP
$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