Azure Azure PowerShell Cloud Shell

How to fix VNet peering with Peering Status – Failed by use of Azure PowerShell

Virtual network peering is a mechanism that seamlessly connects two or more Azure virtual networks (VNets). Once peered, those virtual networks appear as one, and Azure resources, like IaaS Virtual Machines (VMs), can be accessed from both VNets via their private IP Addresses. If you are interested, you can read more about peering at the Microsoft Docs page.

Last week while creating a new peering through the Azure Portal, the result was a created VNet Peer with a PEERING STATUS Failed.

Next to that, when trying to delete the newly created Peering trough the Azure Portal, this also failed. Probably something went wrong in the back or the Azure Portal was stuck and giving failure, showing the Failed status as a result. Luckily, like in most cases when you are troubleshooting Azure issues, Azure PowerShell came to the rescue.

By running below Azure PowerShell script, directly in Azure Cloud Shell, I was able to get the resources updated using the get and set command, which in the end successfully Connected the VNet peer.

PowerShell script

<#

.SYNOPSIS

A script used to fix VNet Peering with a PEERING STATUS Failed.

.DESCRIPTION

A script used to fix VNet Peering with a PEERING STATUS Failed.

.NOTES

Filename:       VNet_Peering_Status_Failed.ps1.
Created:        11/12/2019
Last modified:  11/12/2019
Author:         Wim Matthyssen
PowerShell:     Azure Cloud Shell or Azure PowerShell 
Version:        Install latest modules if using Azure PowerShell
Action:         Change variables were needed to fit your needs
Disclaimer:     This script is provided "As IS" with no warranties.

.EXAMPLE

.\VNet_Peering_Status_Failed.ps1

.LINK

https://wmatthyssen.com/2019/12/11/configuring-vnet-peering-through-the-azure-portal-resulted-in-a-peering-status-failed/

#>

## Variables

$rgName = "azure-rg"

$vnetName = "azure-vn"

$vnetPeeringName = "vnet-peer-x-2-x"

##------------------------------------------------------------------------------------

## Get VNet Peering

$vnPeer = Get-AzureRmVirtualNetworkPeering -Name $vnetPeeringName -VirtualNetworkName $vnetName -ResourceGroupName $rgName

## Update VNet peering

Set-AzureRmVirtualNetworkPeering -VirtualNetworkPeering $vnPeer

## -----------------------------------------------------------------------------------

I hope the above script comes in handy whenever you face the same issue, and if you have any questions please feel free to leave a comment.

0 comments on “How to fix VNet peering with Peering Status – Failed by use of Azure PowerShell

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: