Add-​Azure​Rm​Virtual​Network​Peering

Creates a peering between two virtual networks.

Syntax

Add-AzureRmVirtualNetworkPeering
   [-AllowForwardedTraffic]
   [-AllowGatewayTransit]
   [-BlockVirtualNetworkAccess]
   -Name <String>
   -RemoteVirtualNetworkId <String>
   [-UseRemoteGateways]
   -VirtualNetwork <PSVirtualNetwork>
   [<CommonParameters>]

Description

The Add-AzureRmVirtualNetworkPeering cmdlet creates a peering between two virtual networks.

Examples

Example 1: Create a peering between two virtual networks

PS C:\>$vnet1 = Get-AzureRmVirtualNetwork -ResourceGroupName "MyResourceGroup" -Name "vnet1"
PS C:\> $vnet2 = Get-AzureRmVirtualNetwork -ResourceGroupName "MyResourceGroup" -Name "vnet2"
PS C:\> Add-AzureRmVirtualNetworkPeering -Name "LinkToVNet2" -VirtualNetwork "MyVirtualNetwork" -RemoteVirtualNetworkId $vnet2.id
PS C:\> Add-AzureRmVirtualNetworkPeering -Name "LinkToVNet1" -VirtualNetwork "MyVirtualNetwork" -RemoteVirtualNetworkId $vnet1.id

The first command gets a virtual network object named vnet1, and then stores it in the $vnet1 variable.

The second command gets a virtual network object named vnet2, and then stores it in the $vnet2 variable.

The third command adds a virtual network peering link from vnet1 to vnet2. This link is named LinkToVnet2.

The fourth command adds a link from vnet2 to vnet1 named LinkToVnet1.

Note that vnet1 and vnet2 are assumed to already exist in this example. Also note that a link must be created from vnet1 to vnet2 and vice versa in order for peering to work.

Required Parameters

-Name

Specifies the name of the virtual network peering.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-RemoteVirtualNetworkId

Specifies the ID of the remote virtual network.

Type:String
Position:Named
Default value:None
Accept pipeline input:True (ByValue)
Accept wildcard characters:False
-VirtualNetwork

Specifies the parent virtual network.

Type:PSVirtualNetwork
Position:Named
Default value:None
Accept pipeline input:True (ByValue)
Accept wildcard characters:False

Optional Parameters

-AllowForwardedTraffic

Indicates that this cmdlet allows the forwarded traffic from the virtual machines in the remote virtual network.

Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-AllowGatewayTransit

Flag to allow gatewayLinks be used in remote virtual network's link to this virtual network

Type:SwitchParameter
Aliases:AlloowGatewayTransit
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-BlockVirtualNetworkAccess

Indicates that this cmdlet blocks the virtual machines in the linked virtual network space to access all the virtual machines in local virtual network space.

Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-UseRemoteGateways

Indicates that this cmdlet allows remote gateways on this virtual network.

Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False