PowerShell commands for virtual networks and where is peered to.

Nana Poku 140 Reputation points
2025-01-30T11:59:45.83+00:00

PowerShell commands for all virtual networks and where is peered to in azure tenant.

Azure Virtual Network
Azure Virtual Network
An Azure networking service that is used to provision private networks and optionally to connect to on-premises datacenters.
2,611 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,779 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rohith Vinnakota 2,180 Reputation points Microsoft Vendor
    2025-01-30T12:48:18.2966667+00:00

    Hi @Nana Poku,

    I understand that you require all virtual networks that are peered within the tenant.

    $vnets = Get-AzVirtualNetwork
    foreach ($vnet in $vnets) {
        Write-Host "VNet Name: $($vnet.Name)"
        if ($vnet.VirtualNetworkPeerings.Count -gt 0) {
            foreach ($peering in $vnet.VirtualNetworkPeerings) {
                Write-Host "Peered with: $($peering.RemoteVirtualNetwork.Id)"
            }
        } else {
            Write-Host "No peerings found."
        }
    }
    

    I hope it helps.


    If above is unclear and/or you are unsure about something add a comment below.

    Please don’t forget to close the thread by clicking "Accept the answer" wherever the information provided helps you, as this can be beneficial to other community members.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.