< Back
Add-AzureRmVirtualNetworkPeering
Post
NAME Add-AzureRmVirtualNetworkPeering
SYNOPSIS
Creates a peering between two virtual networks.
SYNTAX
Add-AzureRmVirtualNetworkPeering [-AllowForwardedTraffic] [-AllowGatewayTransit] [-AsJob] [-BlockVirtualNetworkAccess] [-DefaultProfile
<IAzureContextContainer>] -Name <String> -RemoteVirtualNetworkId <String> [-UseRemoteGateways] -VirtualNetwork <PSVirtualNetwork>
[<CommonParameters>]
DESCRIPTION
The Add-AzureRmVirtualNetworkPeering cmdlet creates a peering between two virtual networks.
PARAMETERS
-AllowForwardedTraffic [<SwitchParameter>]
Indicates that this cmdlet allows the forwarded traffic from the virtual machines in the remote virtual network.
Required? false
Position? named
Default value False
Accept pipeline input? False
Accept wildcard characters? false
-AllowGatewayTransit [<SwitchParameter>]
Flag to allow gatewayLinks be used in remote virtual network's link to this virtual network
Required? false
Position? named
Default value False
Accept pipeline input? False
Accept wildcard characters? false
-AsJob [<SwitchParameter>]
Run cmdlet in the background
Required? false
Position? named
Default value False
Accept pipeline input? False
Accept wildcard characters? false
-BlockVirtualNetworkAccess [<SwitchParameter>]
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.
Required? false
Position? named
Default value False
Accept pipeline input? False
Accept wildcard characters? false
-DefaultProfile <IAzureContextContainer>
The credentials, account, tenant, and subscription used for communication with azure.
Required? false
Position? named
Default value None
Accept pipeline input? False
Accept wildcard characters? false
-Name <String>
Specifies the name of the virtual network peering.
Required? true
Position? named
Default value None
Accept pipeline input? False
Accept wildcard characters? false
-RemoteVirtualNetworkId <String>
Specifies the ID of the remote virtual network.
Required? true
Position? named
Default value None
Accept pipeline input? True (ByValue)
Accept wildcard characters? false
-UseRemoteGateways [<SwitchParameter>]
Indicates that this cmdlet allows remote gateways on this virtual network.
Required? false
Position? named
Default value False
Accept pipeline input? False
Accept wildcard characters? false
-VirtualNetwork <PSVirtualNetwork>
Specifies the parent virtual network.
Required? true
Position? named
Default value None
Accept pipeline input? True (ByValue)
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
String
Parameter 'RemoteVirtualNetworkId' accepts value of type 'String' from the pipeline
PSVirtualNetwork
Parameter 'VirtualNetwork' accepts value of type 'PSVirtualNetwork' from the pipeline
OUTPUTS
Microsoft.Azure.Commands.Network.Models.PSVirtualNetworkPeering
NOTES
Example 1: Create a peering between two virtual networks in the same region
# Variables for common values used throughout the script.
$rgName='myResourceGroup'
$location='eastus'
# Create a resource group.
New-AzureRmResourceGroup -Name $rgName -Location $location
# Create virtual network 1.
$vnet1 = New-AzureRmVirtualNetwork -ResourceGroupName $rgName -Name 'myVnet1' -AddressPrefix '10.0.0.0/16' -Location $location
# Create virtual network 2.
$vnet2 = New-AzureRmVirtualNetwork -ResourceGroupName $rgName -Name 'myVnet2' -AddressPrefix '10.1.0.0/16' -Location $location
# Peer VNet1 to VNet2.
Add-AzureRmVirtualNetworkPeering -Name myVnet1ToMyVnet2' -VirtualNetwork $vnet1 -RemoteVirtualNetworkId $vnet2.Id
# Peer VNet2 to VNet1.
Add-AzureRmVirtualNetworkPeering -Name 'myVnet2ToMyVnet1' -VirtualNetwork $vnet2 -RemoteVirtualNetworkId $vnet1.Id
Note that a peering link must be created from vnet1 to vnet2 and vice versa in order for peering to work.
Example 2: Create a peering between two virtual networks in different regions
# Variables for common values used throughout the script.
$rgName='myResourceGroup'
# Create a resource group.
New-AzureRmResourceGroup -Name $rgName -Location westcentralus
# Create virtual network 1.
$vnet1 = New-AzureRmVirtualNetwork -ResourceGroupName $rgName -Name 'myVnet1' -AddressPrefix '10.0.0.0/16' -Location westcentralus
# Create virtual network 2.
$vnet2 = New-AzureRmVirtualNetwork -ResourceGroupName $rgName -Name 'myVnet2' -AddressPrefix '10.1.0.0/16' -Location candacentral
# Peer VNet1 to VNet2.
Add-AzureRmVirtualNetworkPeering -Name myVnet1ToMyVnet2' -VirtualNetwork $vnet1 -RemoteVirtualNetworkId $vnet2.Id
# Peer VNet2 to VNet1.
Add-AzureRmVirtualNetworkPeering -Name 'myVnet2ToMyVnet1' -VirtualNetwork $vnet2 -RemoteVirtualNetworkId $vnet1.Id
Here 'myVnet1' in US West Central is peered with 'myVnet2' in Canada Central.
RELATED LINKS
Online Version: https://docs.microsoft.com/en-us/powers ... orkpeering
Get-AzureRmVirtualNetwork
Get-AzureRmVirtualNetworkPeering
Remove-AzureRmVirtualNetworkPeering
Set-AzureRmVirtualNetworkPeering
SYNOPSIS
Creates a peering between two virtual networks.
SYNTAX
Add-AzureRmVirtualNetworkPeering [-AllowForwardedTraffic] [-AllowGatewayTransit] [-AsJob] [-BlockVirtualNetworkAccess] [-DefaultProfile
<IAzureContextContainer>] -Name <String> -RemoteVirtualNetworkId <String> [-UseRemoteGateways] -VirtualNetwork <PSVirtualNetwork>
[<CommonParameters>]
DESCRIPTION
The Add-AzureRmVirtualNetworkPeering cmdlet creates a peering between two virtual networks.
PARAMETERS
-AllowForwardedTraffic [<SwitchParameter>]
Indicates that this cmdlet allows the forwarded traffic from the virtual machines in the remote virtual network.
Required? false
Position? named
Default value False
Accept pipeline input? False
Accept wildcard characters? false
-AllowGatewayTransit [<SwitchParameter>]
Flag to allow gatewayLinks be used in remote virtual network's link to this virtual network
Required? false
Position? named
Default value False
Accept pipeline input? False
Accept wildcard characters? false
-AsJob [<SwitchParameter>]
Run cmdlet in the background
Required? false
Position? named
Default value False
Accept pipeline input? False
Accept wildcard characters? false
-BlockVirtualNetworkAccess [<SwitchParameter>]
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.
Required? false
Position? named
Default value False
Accept pipeline input? False
Accept wildcard characters? false
-DefaultProfile <IAzureContextContainer>
The credentials, account, tenant, and subscription used for communication with azure.
Required? false
Position? named
Default value None
Accept pipeline input? False
Accept wildcard characters? false
-Name <String>
Specifies the name of the virtual network peering.
Required? true
Position? named
Default value None
Accept pipeline input? False
Accept wildcard characters? false
-RemoteVirtualNetworkId <String>
Specifies the ID of the remote virtual network.
Required? true
Position? named
Default value None
Accept pipeline input? True (ByValue)
Accept wildcard characters? false
-UseRemoteGateways [<SwitchParameter>]
Indicates that this cmdlet allows remote gateways on this virtual network.
Required? false
Position? named
Default value False
Accept pipeline input? False
Accept wildcard characters? false
-VirtualNetwork <PSVirtualNetwork>
Specifies the parent virtual network.
Required? true
Position? named
Default value None
Accept pipeline input? True (ByValue)
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
String
Parameter 'RemoteVirtualNetworkId' accepts value of type 'String' from the pipeline
PSVirtualNetwork
Parameter 'VirtualNetwork' accepts value of type 'PSVirtualNetwork' from the pipeline
OUTPUTS
Microsoft.Azure.Commands.Network.Models.PSVirtualNetworkPeering
NOTES
Example 1: Create a peering between two virtual networks in the same region
# Variables for common values used throughout the script.
$rgName='myResourceGroup'
$location='eastus'
# Create a resource group.
New-AzureRmResourceGroup -Name $rgName -Location $location
# Create virtual network 1.
$vnet1 = New-AzureRmVirtualNetwork -ResourceGroupName $rgName -Name 'myVnet1' -AddressPrefix '10.0.0.0/16' -Location $location
# Create virtual network 2.
$vnet2 = New-AzureRmVirtualNetwork -ResourceGroupName $rgName -Name 'myVnet2' -AddressPrefix '10.1.0.0/16' -Location $location
# Peer VNet1 to VNet2.
Add-AzureRmVirtualNetworkPeering -Name myVnet1ToMyVnet2' -VirtualNetwork $vnet1 -RemoteVirtualNetworkId $vnet2.Id
# Peer VNet2 to VNet1.
Add-AzureRmVirtualNetworkPeering -Name 'myVnet2ToMyVnet1' -VirtualNetwork $vnet2 -RemoteVirtualNetworkId $vnet1.Id
Note that a peering link must be created from vnet1 to vnet2 and vice versa in order for peering to work.
Example 2: Create a peering between two virtual networks in different regions
# Variables for common values used throughout the script.
$rgName='myResourceGroup'
# Create a resource group.
New-AzureRmResourceGroup -Name $rgName -Location westcentralus
# Create virtual network 1.
$vnet1 = New-AzureRmVirtualNetwork -ResourceGroupName $rgName -Name 'myVnet1' -AddressPrefix '10.0.0.0/16' -Location westcentralus
# Create virtual network 2.
$vnet2 = New-AzureRmVirtualNetwork -ResourceGroupName $rgName -Name 'myVnet2' -AddressPrefix '10.1.0.0/16' -Location candacentral
# Peer VNet1 to VNet2.
Add-AzureRmVirtualNetworkPeering -Name myVnet1ToMyVnet2' -VirtualNetwork $vnet1 -RemoteVirtualNetworkId $vnet2.Id
# Peer VNet2 to VNet1.
Add-AzureRmVirtualNetworkPeering -Name 'myVnet2ToMyVnet1' -VirtualNetwork $vnet2 -RemoteVirtualNetworkId $vnet1.Id
Here 'myVnet1' in US West Central is peered with 'myVnet2' in Canada Central.
RELATED LINKS
Online Version: https://docs.microsoft.com/en-us/powers ... orkpeering
Get-AzureRmVirtualNetwork
Get-AzureRmVirtualNetworkPeering
Remove-AzureRmVirtualNetworkPeering
Set-AzureRmVirtualNetworkPeering