Hi Martin Thong, I want to help you with this question.
When I understand you correctly, you want to delete a network address space (including every subnet in the address space), right?
If you want to remove only a specific address space within the virtual network, you’ll need to update the address space configuration. Unfortunately, there isn’t a direct cmdlet to remove just one address space. Instead, you can:
- Update the virtual network configuration to exclude the specific address space.
- Delete the existing virtual network and create a new one without the unwanted address space.
There is no specific PowerShell cmdlet available to do that action.
But you can do the following for example:
Remove Subnets in the Address Range:
If any subnets exist within the address range you want to remove, you must delete those subnets first. Use the Remove-AzVirtualNetworkSubnetConfig
cmdlet to remove a subnet from the virtual network.
For example, if you have a subnet named “Subnet1” within the address range you want to remove, use the following command:
Remove-AzVirtualNetworkSubnetConfig
Update the Address Space:
Use the Get-AzVirtualNetwork
cmdlet to retrieve the current configuration of the virtual network.
Add or remove address prefixes as needed. For example, if your existing virtual network has an address prefix of 10.0.0.0/16
, you can extend it with additional address prefixes using the following commands:
$existingVNet = Get-AzVirtualNetwork -ResourceGroupName "myResourceGroup" -Name "myVNet"
$updatedVNet = $existingVNet | Set-AzVirtualNetwork -AddressPrefix @("10.0.0.0/16", "192.168.0.0/24")
Apply the Changes:
Finally, apply the updated configuration to the virtual network using the Set-AzVirtualNetwork
cmdlet:
Set-AzVirtualNetwork
I hope this will give you a sufficient solution
If the reply was helpful, please don’t forget to upvote or accept it as an answer, thank you!