尝试以下 PowerShell 脚本:
# Delete all Virtual Network resources from resource groups
$resourceGroups = Get-AzResourceGroup
foreach ($resourceGroup in $resourceGroups) {
Get-AzResource -ResourceGroupName $resourceGroup.ResourceGroupName -ResourceType Microsoft.Network/virtualNetworks | Remove-AzResource -Force
}
# Delete specific Virtual Networks resources from resource groups
$resourceGroups = Get-AzResourceGroup
$listOfVirtualNetworksNamesToBeRemoved = @('vnet1','vnet2','vnet3')
foreach ($resourceGroup in $resourceGroups) {
$virtualNetworks = Get-AzResource -ResourceGroupName $resourceGroup.ResourceGroupName -ResourceType Microsoft.Network/virtualNetworks
$virtualNetworks | ForEach-Object {
if($listOfVirtualNetworksNamesToBeRemoved -match $_) {
Remove-AzResource -ResourceId $_.ResourceId -Force
}
}
}