Tuesday, August 09, 2016

Error Creating Cross Subscription VNet-to-VNet Connection on Azure Resource Manager Using PowerShell

So you are trying to create a VNet to VNet connection across subscriptions in Azure Resource Manager. The official documentation states that this cannot done by portal, and only PowerShell is supported:

https://azure.microsoft.com/en-us/documentation/articles/vpn-gateway-vnet-vnet-rm-ps/

When you run the final piece of code to create the connection:

$vnet1gw = New-Object Microsoft.Azure.Commands.Network.Models.PSVirtualNetworkGateway
$vnet1gw.Name = "VNet1GW"
$vnet1gw.Id   = "/subscriptions/b636ca99-6f88-4df4-a7c3-2f8dc4545509/resourceGroups/TestRG1/providers/Microsoft.Network/virtualNetworkGateways/VNet1GW "
New-AzureRmVirtualNetworkGatewayConnection -Name $Connection51 -ResourceGroupName $RG5 -VirtualNetworkGateway1 $vnet5gw -VirtualNetworkGateway2 $vnet1gw -Location $Location5 -ConnectionType Vnet2Vnet -SharedKey 'AzureA1b2C3'

You get the following error message:


UInt64 -> Nullable`1
System.UInt64 -> System.Nullable`1[[System.Int64, mscorlib .....

I was running Azure PowerShell 1.6.0 at the time.

Fix: Upgrade to Azure PowerShell 2.0.0 (download here).

To check your Azure PowerShell version, run the following script:

(Get-Module -ListAvailable | Where-Object{ $_.Name -eq 'Azure' }) `
| Select Version, Name, Author, PowerShellVersion  | Format-List;


No comments: