I have an Azure subscription that I use for test/dev purposes and it was starting to get a little crowded the other day with various labs that I had spun up for a purpose and never removed. So I had a wee spring clean using some handy PowerShell commands.
I covered some basic commands on how to connect to your Azure subscription via PowerShell within my “Connecting to Azure with PowerShell and controlling your VMs” blog post.
Connect to Azure with PowerShell
To log into your Azure account with PowerShell you need to issue the following command, once ran this will launch a pop up box asking you for your credentials:
List your Azure Resource Groups
Find-AzureRmResource | Select-Object ResourceGroupName
This command listed all the names of the Resource Groups I had but it listed them several times, once for each resource in that group. It made the output a bit long winded and cluttered.
I then issued the command:
Find-AzureRmResource | Select-Object ResourceGroupName -Unique
This shortened the list so that it only showed the name of the Resource Group once, must easier to read!
Remove Azure Resource Groups
Now in order to get rid of the Resource Groups I used the following command:
Remove-AzureRMResourceGroup -Name WSUSDEV -Force
The above command removed all the resources within my Resource Group called “WSUSDEV” and didn’t prompt me to check I wanted to carry out the action.