peer-vnet-across-tenant
#declare variables $subscriptionTenantA = "subscriptionID" $vNetTenantA = "vNet" $vnetResourceGroupTenantA = "vNetResourceGroup" $peerAtoBname = "TenantA-TenantB-Peer01" $subscriptionTenantB = "subscriptionID" $vNetTenantB = "vNet" $vnetResourceGroupTenantB = "vNetResourceGroup" $peerBtoAname = "TenantB-TenantA-Peer01" #connect to AzureRM Connect-AzAccount #select subscription in Tenant A Select-AzSubscription -Subscription $subscriptionTenantA #peer vnet in tenant A to vnet in tenant B $vNet = Get-AzVirtualNetwork -Name $vNetTenantA -ResourceGroupName $vnetResourceGroupTenantA Add-AzVirtualNetworkPeering -Name $peerAtoBname -VirtualNetwork $vNet -RemoteVirtualNetworkId "/subscriptions/$subscriptionTenantB/resourceGroups/$vnetResourceGroupTenantB/providers/Microsoft.Network/virtualNetworks/$vNetTenantB" #select subscription in Tenant B Select-AzSubscription -Subscription $subscriptionTenantB #peer vnet in tenant B to vnet in tenant A $vNet = Get-AzVirtualNetwork -Name $vNetTenantB -ResourceGroupName $vnetResourceGroupTenantB Add-AzVirtualNetworkPeering -Name $peerBtoAname -VirtualNetwork $vNet -RemoteVirtualNetworkId "/subscriptions/$subscriptionTenantA/resourceGroups/$vnetResourceGroupTenantA/providers/Microsoft.Network/virtualNetworks/$vNetTenantA"