我有下面的代码,但是我无法从
$subnets
循环获取名称并在代码中使用它。我想要做的是删除虚拟网络中的所有子网。
$rg = "xxxx"
$vnet = "dddd"
$subnets = az network vnet subnet list --resource-group $rg --vnet-name $vnet
foreach ($subnet in $subnets.name)
{
write-host $subnet
az network vnet subnet delete --name $subnet --resource-group $rg --vnet-name $vnet
}
我已修改代码以从
$subnets
循环以获取名称并在代码中使用它
$rg = "<RGName>"
$vnet = "<vnetName>"
$subnets = az network vnet subnet list --resource-group $rg --vnet-name $vnet | ConvertFrom-Json
foreach ($subnet in $subnets)
{
write-host $subnet.name
az network vnet subnet delete --name $subnet.name --resource-group $rg --vnet-name $vnet
}
当我运行上面的代码时,子网已成功列出:
为了确认这一点,我在门户中检查了相同的内容,子网已成功删除,如下所示: