Skip to content

Instantly share code, notes, and snippets.

@dazfuller
Created June 14, 2017 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dazfuller/f10cbc57a2b1c5b95d6c45064041b5ae to your computer and use it in GitHub Desktop.
Save dazfuller/f10cbc57a2b1c5b95d6c45064041b5ae to your computer and use it in GitHub Desktop.
Find the primary private IP address of VMs in Azure
$VMs = Get-AzureRmVM
$Results = @()
ForEach ($VM in $VMs)
{
ForEach ($NicID in $VM.NetworkInterfaceIDs)
{
$Nic = Get-AzureRmResource -ResourceId $NicID | Get-AzureRmNetworkInterface
$Result = New-Object PSObject
$Result | Add-Member -MemberType NoteProperty -Name "ResourceGroupName" -Value $VM.ResourceGroupName
$Result | Add-Member -MemberType NoteProperty -Name "VMName" -Value $VM.Name
$Result | Add-Member -MemberType NoteProperty -Name "NicName" -Value $Nic.Name
$Result | Add-Member -MemberType NoteProperty -Name "PrivateIpAddress" -Value $Nic.IpConfigurations[0].PrivateIpAddress
$Results += $Result
}
}
$Results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment