gpt4 book ai didi

azure - 为什么azure子网没有subnet.id参数

转载 作者:行者123 更新时间:2023-12-03 02:50:13 25 4
gpt4 key购买 nike

我有以下简单代码来生成 3 个子网:

$resourceGroupName = "Test1"
$location = "West Europe"
$VNetName = "Test-VM"
$VNetIPRange = "192.168.0.0/21"
$SubnetAName = "SubA"
$SubnetAIPRange = "192.168.0.0/24"
$SubnetBName = "SubB"
$SubnetBIPRange = "192.168.1.0/24"
$SubnetCName = "SubC"
$SubnetCIPRange = "192.168.2.0/24"

New-AzResourceGroup -name $resourceGroupName -Location $location -Verbose

# subnets & vnet
$subnets = New-AzVirtualNetworkSubnetConfig `
-Name $SubnetAName `
-AddressPrefix $SubnetAIPRange `
-Verbose
$vnet = New-AzVirtualNetwork `
-Name $VNetName `
-AddressPrefix $VNetIPRange `
-Subnet $subnets `
-ResourceGroupName $resourceGroupName `
-Location $location `
-Verbose
Add-AzVirtualNetworkSubnetConfig `
-VirtualNetwork $vnet `
-Name $SubnetBName `
-AddressPrefix $SubnetBIPRange `
-Verbose
Add-AzVirtualNetworkSubnetConfig `
-VirtualNetwork $vnet `
-Name $SubnetCName `
-AddressPrefix $SubnetCIPRange `
-Verbose
Set-AzVirtualNetwork `
-VirtualNetwork $vnet `
-Verbose

代码成功运行并生成了预期的内容,但有一点异常(exception)。只有 SubA 拥有完整信息。对于子网 B 和 C,仅以下配置如下:

                       {
"Name": "SubB",
"AddressPrefix": [
"192.168.1.0/24"
]
}

这样我就无法引用子网 ID,例如:

  -SubnetId $vnet.Subnets[1].Id `

因为该字段为空:(

代码中是否有问题,或者我应该引用不同的子网 ID?

我想将一些虚拟机放置在不同的子网中,并且在运行上述代码后只有 SubA 具有 SubnetID。

                     {
"Delegations": [],
"Name": "SubA",
"Etag": "W/\"01baac3e-3fc3-400b-a6f1-64b08f5b45e7\"",
"Id": "/subscriptions/XXX/resourceGroups/Test1/providers/Microsoft.Network/virtua
lNetworks/Test-VM/subnets/SubA",
"AddressPrefix": [
"192.168.0.0/24"
],
"IpConfigurations": [],
"ServiceAssociationLinks": [],
"ResourceNavigationLinks": [],
"ServiceEndpoints": [],
"ServiceEndpointPolicies": [],
"InterfaceEndpoints": [],
"ProvisioningState": "Succeeded"
},

最佳答案

我测试了你的代码,我可以重现你的问题,只需在你的代码后使用 Get-AzVirtualNetwork ,然后你就可以获得另外两个的 Id子网。

$vnet = Get-AzVirtualNetwork -ResourceGroupName $resourceGroupName -Name $VNetName
$vnet.Subnets[1].Id
$vnet.Subnets[2].Id

enter image description here

关于azure - 为什么azure子网没有subnet.id参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56515073/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com