Skip to content

Instantly share code, notes, and snippets.

@eosfor
Created July 23, 2018 09:03
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 eosfor/5bfb6b7958b337b7ff83b3d390f156c0 to your computer and use it in GitHub Desktop.
Save eosfor/5bfb6b7958b337b7ff83b3d390f156c0 to your computer and use it in GitHub Desktop.
Join Vm info, NIC info and Public IP info
$rgName = "kubetest"
$vms = Get-AzureRmVM -ResourceGroupName $rgName
$nics = Get-AzureRmNetworkInterface -ResourceGroupName $rgName
$pubIPs = Get-AzureRmPublicIpAddress -ResourceGroupName $rgName
$vmNics = @{}
$nics | ForEach-Object {
$index = $_.id
$value = $_
$vmNics[$index] += @($value)
}
$ipConfigs = @{}
$pubIPs | ForEach-Object {
$index = $_.IpConfiguration.id
$value = $_
$ipConfigs[$index] += @($value)
}
$vms | ForEach-Object {
$vm = $_
$nicIndex = $vm.NetworkProfile.NetworkInterfaces.id
$nic = $vmNics[$nicIndex]
$configIndex = $nic.IpConfigurations.id
$ipConfig = $ipConfigs[$configIndex]
[pscustomobject]@{VMName = $vm.Name;
ComputerName = $vm.OSProfile.ComputerName;
PrivateIP = $nic.IpConfigurations.PrivateIpAddress;
PublicIP = $ipConfig.IpAddress}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment