问题创建vnets在不同订阅中的对等体。 [英] Issue creating peers where vnets are in different subscriptions.

查看:48
本文介绍了问题创建vnets在不同订阅中的对等体。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用add-azvirtualnetworkpeering在PowerShell脚本(Az最新)中使用现有的vnet对等配置。这两个vnet在不同的订阅中。看来我必须为虚拟网络和远程网络交换机使用变量。我可以将订阅上下文设置为1并应用get-azvirtualnetwork将其分配给$ vnet1,然后将上下文切换到其他订阅上下文并分配第二个$ vnet2值。但是当我运行add-azvirtualnetworkpeering命令(来自任一订阅上下文)时,它给我'找不到匹配参数'virtualnetwork'或'remotenetwork'的参数,具体取决于我所处的上下文。请参阅示例2 https:// docs.microsoft.com/en-us/powershell/module/az.network/add-azvirtualnetworkpeering?view=azps-1.6.0除了已创建RG并且我使用get-azvirtualnetwork代替新的azvirtualnetwork他们已经存在了。代码如下所示:

PS C:> set-azcontext(get-azsubscription -subscriptionname'1')PS C:> $ vnet1 = get-azvirtualnetwork -name'vnet1'PS C: > set-azcontext(get-azsubscription -subscriptionname'2')PS C:> $ vnet2 = get-azvirtualnetwork -name'vnet2'PS C:> add-azvirtualnetworkpeering -name'vnet1tovnet2'-virtualnetwork $ vnet1 -remotenetwork $ vnet2.id -AllowForwardedTraffic

我收到此错误:

Add-AzVirtualNetworkPeering:找不到与参数名称'remotenetwork'匹配的参数。在行:1 char:99 + ... vnet1tovnet2'-virtualnetwork $ vnetfrom -remotenetwork $ vnet2 ... + ~~~~~~~~~~~~~~ + CategoryInfo:InvalidArgument:(:) [Add- AzVirtualNetworkPeering],ParameterBindingException + FullyQualifiedErrorId:NamedParameterNotFound,Microsoft.Azure.Commands.Network.AddAzureVirtualNetworkPeeringCommand


解决方案

您好macombej,


您能否确保在add-azvirtualnetworkpeering命令中将-RemoteVirtualNetworkId作为输入参数而非-remotenetwork提供。 


下面的代码片段对您的情况应该有帮助,
文档
供参考 

#Get Virtual Network 1 

vnet1 = Get-AzVirtualNetwork -Name'vnet1'

#获取虚拟网络2.

vnet2 = Get-AzVirtualNetwork -Name'vnet2'

#Peer VNet1 to VNet2。
Add-AzVirtualNetworkPeering -Name'vnet1tovnet2'-VirtualNetwork


I am trying to powershell script (Az latest) an existing vnet peering configuration using add-azvirtualnetworkpeering. The two vnets are in different subscriptions. It appears I must use a variable for the virtualnetwork and remotenetwork switches. I can set my subscription context for 1 and apply get-azvirtualnetwork assigning it to $vnet1, then switch context to the other subscription context and assign the second $vnet2 value. But when I run the add-azvirtualnetworkpeering command (from either subscription context) it gives me 'A parameter cannot be found that matches parameter 'virtualnetwork' or 'remotenetwork' depending on which context I am in. See example 2 here https://docs.microsoft.com/en-us/powershell/module/az.network/add-azvirtualnetworkpeering?view=azps-1.6.0 except the RG is already created and I use a get-azvirtualnetwork in place of the new-azvirtualnetwork since they already exist. Code looks like this:

PS C:>set-azcontext (get-azsubscription -subscriptionname '1') PS C:>$vnet1 = get-azvirtualnetwork -name 'vnet1' PS C:>set-azcontext (get-azsubscription -subscriptionname '2') PS C:>$vnet2 = get-azvirtualnetwork -name 'vnet2' PS C:>add-azvirtualnetworkpeering -name 'vnet1tovnet2' -virtualnetwork $vnet1 -remotenetwork $vnet2.id -AllowForwardedTraffic

I get this error:

Add-AzVirtualNetworkPeering : A parameter cannot be found that matches parameter name 'remotenetwork'. At line:1 char:99 + ... vnet1tovnet2' -virtualnetwork $vnetfrom -remotenetwork $vnet2 ... + ~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Add-AzVirtualNetworkPeering], ParameterBindingException + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.Azure.Commands.Network.AddAzureVirtualNetworkPeeringCommand

解决方案

Hi macombej,

Can you please make sure that the -RemoteVirtualNetworkId is provided as an input parameter instead of -remotenetwork in the add-azvirtualnetworkpeering command. 

Below code snippet should help in your case, documentation for reference 

# Get Virtual Network 1


vnet1 = Get-AzVirtualNetwork -Name 'vnet1' # Get Virtual Network 2.


vnet2 = Get-AzVirtualNetwork -Name 'vnet2' # Peer VNet1 to VNet2. Add-AzVirtualNetworkPeering -Name 'vnet1tovnet2' -VirtualNetwork


这篇关于问题创建vnets在不同订阅中的对等体。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆