Azure 对等互连的输出
Output of Azure Peerings
我目前正在编写一个脚本,该脚本为我提供 Azure 订阅中每个对等互连的输出,其中列出了 VNet 和一些选项,例如 AllowVirtualNetworkAccess、AllowForwardedTraffic、UseRemoteGateways 和 AllowGatewayTransit。输出应如下所示:
Peering Name VNet 1 VNet 2 AllowVirtualNetworkAccess AllowForwardedTraffic UseRemoteGateways AllowGatewayTransit
------------ ------ ------ ------------------------- --------------------- ----------------- -------------------
test-peering vnet-ine-test vnet-chn-docker False True False False
vnet-docker-test vnet-chn-docker vnet-ine-test True True False False
这是我的脚本目前的样子:
$VNets = Get-AzVirtualNetwork
$peerings=@()
$peeringInfo = @{ "Peering Name"="" ; "VNet 1"="" ; "VNet 2"="" ; "AllowVirtualNetworkAccess"="" ; "AllowForwardedTraffic"="" ; "UseRemoteGateways"="" ; "AllowGatewayTransit"=""}
foreach($VNet in $VNets){
$peeringInfo.'Peering Name'=$VNet.VirtualNetworkPeerings.Name
$peeringInfo.'AllowVirtualNetworkAccess'=$VNet.VirtualNetworkPeerings.Name
$peeringInfo.'AllowForwardedTraffic'=$VNet.VirtualNetworkPeerings.Name
$peeringInfo.'UseRemoteGateways'=$VNet.VirtualNetworkPeerings.Name
$peeringInfo.'AllowGatewayTransit'=$VNet.VirtualNetworkPeerings.Name
$peering = Get-AzVirtualNetworkPeering -VirtualNetworkName $VNet.Name -ResourceGroupName $VNet.ResourceGroupName
foreach($peer in $peering){
$peeringInfo.'VNet 1' =$peer.VirtualNetworkName
$peeringInfo.'VNet 2' =(Get-AzVirtualNetwork -Name $peer.RemoteVirtualNetwork.Id).Name
$obj=New-Object PSObject -Property $peeringInfo
$peerings +=$obj
}
}
$peerings | Format-Table "Peering Name","VNet 1","VNet 2",AllowVirtualNetworkAccess,AllowForwardedTraffic,UseRemoteGateways,AllowGatewayTransit
这是输出:
Peering Name VNet 1 VNet 2 AllowVirtualNetworkAccess AllowForwardedTraffic UseRemoteGateways AllowGatewayTransit
------------ ------ ------ ------------------------- --------------------- ----------------- -------------------
test-peering vnet-ine-test {vnet-ine-test, vnet-chn-docker} test-peering test-peering test-peering test-peering
vnet-docker-test vnet-chn-docker {vnet-ine-test, vnet-chn-docker} vnet-docker-test vnet-docker-test vnet-docker-test vnet-docker-test
我知道问题必须与行 $peeringInfo.'VNet 2' =(Get-AzVirtualNetwork -Name $peer.RemoteVirtualNetwork.Id).Name
相关,因为当我只是 运行 (Get-AzVirtualNetwork -Name $peer.RemoteVirtualNetwork.Id).Name
时有两个输出,这很奇怪,因为
$peer.RemoteVirtualNetwork.Id 应该只有一个值。
所以我找到了答案。它实际上是 $peeringInfo.'VNet 2' =(Get-AzVirtualNetwork | Where-Object ID -EQ $peer.RemoteVirtualNetwork.Id).Name
行。它现在已更改为 Where-Object,以比较 ID,而不是搜索名称。这是完整的脚本:
$VNets = Get-AzVirtualNetwork
$peerings=@()
$peeringInfo = @{ "Peering Name"="" ; "VNet 1"="" ; "VNet 2"="" ; "AllowVirtualNetworkAccess"="" ; "AllowForwardedTraffic"="" ; "UseRemoteGateways"="" ; "AllowGatewayTransit"=""}
foreach($VNet in $VNets){
$peeringInfo.'Peering Name'=$VNet.VirtualNetworkPeerings.Name
$peeringInfo.'AllowVirtualNetworkAccess'=$VNet.VirtualNetworkPeerings.AllowVirtualNetworkAccess
$peeringInfo.'AllowForwardedTraffic'=$VNet.VirtualNetworkPeerings.AllowForwardedTraffic
$peeringInfo.'UseRemoteGateways'=$VNet.VirtualNetworkPeerings.UseRemoteGateways
$peeringInfo.'AllowGatewayTransit'=$VNet.VirtualNetworkPeerings.AllowGatewayTransit
$peering = Get-AzVirtualNetworkPeering -VirtualNetworkName $VNet.Name -ResourceGroupName $VNet.ResourceGroupName
foreach($peer in $peering){
$peeringInfo.'VNet 1' =$peer.VirtualNetworkName
$peeringInfo.'VNet 2' =(Get-AzVirtualNetwork | Where-Object ID -EQ $peer.RemoteVirtualNetwork.Id).Name
$obj=New-Object PSObject -Property $peeringInfo
$peerings +=$obj
}
}
$peerings | Format-Table "Peering Name","VNet 1","VNet 2",AllowVirtualNetworkAccess,AllowForwardedTraffic,UseRemoteGateways,AllowGatewayTransit
这是输出:
Peering Name VNet 1 VNet 2 AllowVirtualNetworkAccess AllowForwardedTraffic UseRemoteGateways AllowGatewayTransit
------------ ------ ------ ------------------------- --------------------- ----------------- -------------------
test-peering vnet-ine-test vnet-chn-docker False True False False
vnet-docker-test vnet-chn-docker vnet-ine-test True True False False
我目前正在编写一个脚本,该脚本为我提供 Azure 订阅中每个对等互连的输出,其中列出了 VNet 和一些选项,例如 AllowVirtualNetworkAccess、AllowForwardedTraffic、UseRemoteGateways 和 AllowGatewayTransit。输出应如下所示:
Peering Name VNet 1 VNet 2 AllowVirtualNetworkAccess AllowForwardedTraffic UseRemoteGateways AllowGatewayTransit
------------ ------ ------ ------------------------- --------------------- ----------------- -------------------
test-peering vnet-ine-test vnet-chn-docker False True False False
vnet-docker-test vnet-chn-docker vnet-ine-test True True False False
这是我的脚本目前的样子:
$VNets = Get-AzVirtualNetwork
$peerings=@()
$peeringInfo = @{ "Peering Name"="" ; "VNet 1"="" ; "VNet 2"="" ; "AllowVirtualNetworkAccess"="" ; "AllowForwardedTraffic"="" ; "UseRemoteGateways"="" ; "AllowGatewayTransit"=""}
foreach($VNet in $VNets){
$peeringInfo.'Peering Name'=$VNet.VirtualNetworkPeerings.Name
$peeringInfo.'AllowVirtualNetworkAccess'=$VNet.VirtualNetworkPeerings.Name
$peeringInfo.'AllowForwardedTraffic'=$VNet.VirtualNetworkPeerings.Name
$peeringInfo.'UseRemoteGateways'=$VNet.VirtualNetworkPeerings.Name
$peeringInfo.'AllowGatewayTransit'=$VNet.VirtualNetworkPeerings.Name
$peering = Get-AzVirtualNetworkPeering -VirtualNetworkName $VNet.Name -ResourceGroupName $VNet.ResourceGroupName
foreach($peer in $peering){
$peeringInfo.'VNet 1' =$peer.VirtualNetworkName
$peeringInfo.'VNet 2' =(Get-AzVirtualNetwork -Name $peer.RemoteVirtualNetwork.Id).Name
$obj=New-Object PSObject -Property $peeringInfo
$peerings +=$obj
}
}
$peerings | Format-Table "Peering Name","VNet 1","VNet 2",AllowVirtualNetworkAccess,AllowForwardedTraffic,UseRemoteGateways,AllowGatewayTransit
这是输出:
Peering Name VNet 1 VNet 2 AllowVirtualNetworkAccess AllowForwardedTraffic UseRemoteGateways AllowGatewayTransit
------------ ------ ------ ------------------------- --------------------- ----------------- -------------------
test-peering vnet-ine-test {vnet-ine-test, vnet-chn-docker} test-peering test-peering test-peering test-peering
vnet-docker-test vnet-chn-docker {vnet-ine-test, vnet-chn-docker} vnet-docker-test vnet-docker-test vnet-docker-test vnet-docker-test
我知道问题必须与行 $peeringInfo.'VNet 2' =(Get-AzVirtualNetwork -Name $peer.RemoteVirtualNetwork.Id).Name
相关,因为当我只是 运行 (Get-AzVirtualNetwork -Name $peer.RemoteVirtualNetwork.Id).Name
时有两个输出,这很奇怪,因为
$peer.RemoteVirtualNetwork.Id 应该只有一个值。
所以我找到了答案。它实际上是 $peeringInfo.'VNet 2' =(Get-AzVirtualNetwork | Where-Object ID -EQ $peer.RemoteVirtualNetwork.Id).Name
行。它现在已更改为 Where-Object,以比较 ID,而不是搜索名称。这是完整的脚本:
$VNets = Get-AzVirtualNetwork
$peerings=@()
$peeringInfo = @{ "Peering Name"="" ; "VNet 1"="" ; "VNet 2"="" ; "AllowVirtualNetworkAccess"="" ; "AllowForwardedTraffic"="" ; "UseRemoteGateways"="" ; "AllowGatewayTransit"=""}
foreach($VNet in $VNets){
$peeringInfo.'Peering Name'=$VNet.VirtualNetworkPeerings.Name
$peeringInfo.'AllowVirtualNetworkAccess'=$VNet.VirtualNetworkPeerings.AllowVirtualNetworkAccess
$peeringInfo.'AllowForwardedTraffic'=$VNet.VirtualNetworkPeerings.AllowForwardedTraffic
$peeringInfo.'UseRemoteGateways'=$VNet.VirtualNetworkPeerings.UseRemoteGateways
$peeringInfo.'AllowGatewayTransit'=$VNet.VirtualNetworkPeerings.AllowGatewayTransit
$peering = Get-AzVirtualNetworkPeering -VirtualNetworkName $VNet.Name -ResourceGroupName $VNet.ResourceGroupName
foreach($peer in $peering){
$peeringInfo.'VNet 1' =$peer.VirtualNetworkName
$peeringInfo.'VNet 2' =(Get-AzVirtualNetwork | Where-Object ID -EQ $peer.RemoteVirtualNetwork.Id).Name
$obj=New-Object PSObject -Property $peeringInfo
$peerings +=$obj
}
}
$peerings | Format-Table "Peering Name","VNet 1","VNet 2",AllowVirtualNetworkAccess,AllowForwardedTraffic,UseRemoteGateways,AllowGatewayTransit
这是输出:
Peering Name VNet 1 VNet 2 AllowVirtualNetworkAccess AllowForwardedTraffic UseRemoteGateways AllowGatewayTransit
------------ ------ ------ ------------------------- --------------------- ----------------- -------------------
test-peering vnet-ine-test vnet-chn-docker False True False False
vnet-docker-test vnet-chn-docker vnet-ine-test True True False False