All scripts
Azure AI 269

Get-AzureVMNetworkInterfaceReport

Reports every VM's network interfaces with private and public IP assignment and the NSG attached, useful for a network inventory without opening each VM's overview page.

Get-AzureVMNetworkInterfaceReport.ps1
<#
.SYNOPSIS
    Reports network interface details for all VMs.

.DESCRIPTION
    Lists every VM's network interfaces with private IP, public IP
    assignment, and attached network security group, useful for
    building a network inventory without opening each VM's overview
    page individually.

.EXAMPLE
    .\Get-AzureVMNetworkInterfaceReport.ps1

.NOTES
    Requires the Az.Compute and Az.Network modules and an active
    Connect-AzAccount session.

.AUTHOR
    Shehryar Hassan
#>

$vms = Get-AzVM

$report = foreach ($vm in $vms) {
    foreach ($nicRef in $vm.NetworkProfile.NetworkInterfaces) {
        $nic = Get-AzNetworkInterface -ResourceId $nicRef.Id
        $publicIp = if ($nic.IpConfigurations[0].PublicIpAddress) {
            (Get-AzPublicIpAddress -ResourceId $nic.IpConfigurations[0].PublicIpAddress.Id).IpAddress
        } else { "None" }

        [pscustomobject]@{
            VMName    = $vm.Name
            PrivateIP = $nic.IpConfigurations[0].PrivateIpAddress
            PublicIP  = $publicIp
            NSG       = if ($nic.NetworkSecurityGroup) { ($nic.NetworkSecurityGroup.Id -split "/")[-1] } else { "None" }
        }
    }
}

$report | Format-Table -AutoSize

Read it before you run it, and test in a safe tenant first.