查看azure 公网ip 等

$vms = get-azurermvm

$nics = get-azurermnetworkinterface  | where VirtualMachine -NE $null #skip Nics with no VM

foreach($nic in $nics)
{
    $vm = $vms | where-object -Property Id -EQ $nic.VirtualMachine.id
    $vmSize=$vm.HardwareProfile.VmSize
    $rg=$vm.ResourceGroupName
    #$nicId = $nic.id
    $NIC_name =  $nic.id.Substring($nic.id.LastIndexOf('/') + 1)
    $prv =  $nic.IpConfigurations | select-object -ExpandProperty PrivateIpAddress
    $alloc =  $nic.IpConfigurations | select-object -ExpandProperty PrivateIpAllocationMethod
    $pipId = $nic.IpConfigurations[0].PublicIpAddress.Id | where $nic.IpConfigurations.Count -NE 0
    if ( $pipId)
    {
       $pipName = $pipId.Substring($pipId.LastIndexOf('/') + 1) |where $pipId  -NE 0
       $pipAddr = Get-AzureRmPublicIpAddress -Name $pipName -ResourceGroupName $rg
       $pip=$pipAddr.IpAddress
       Write-Output "$rg, $($vm.Location),$($vm.Name) : $vmSize, $NIC_name :  $prv , $pip"
     }
    else
     {
       Write-Output "$rg, $($vm.Location),$($vm.Name) : $vmSize, $NIC_name :  $prv "
     }
}

你可能感兴趣的:(查看azure 公网ip 等)