Resource specific azcli commands:¶
Listing resources:¶
$ az resource list
[[ large amounts of json snipped]]
By itself, this command probably isn’t overly useful but it’s the start of the following.
Listing resource in table format:¶
$ az resource list --query '[].[name,type,changedTime]' --output table
Column1 Column2 Column3
------------ ------------------------------------------- --------------------------------
dkoleary_ssh Microsoft.Compute/sshPublicKeys 2022-05-28T12:54:54.473038+00:00
mycont1 Microsoft.ContainerInstance/containerGroups 2022-05-28T18:34:27.848809+00:00
mycont2 Microsoft.ContainerInstance/containerGroups 2022-05-28T18:34:29.713845+00:00
mycont3 Microsoft.ContainerInstance/containerGroups 2022-05-28T18:34:32.163980+00:00
mycont4 Microsoft.ContainerInstance/containerGroups 2022-05-28T18:34:34.798607+00:00
mycont5 Microsoft.ContainerInstance/containerGroups 2022-05-28T18:34:36.547120+00:00
Remove objects with specifc text in name:¶
az resource list --query '[].[name,type,
resourceGroup,changedTime]' --output table | grep ^ub | awk '{print $1, $2}' | while read n t
do
echo az resource delete -g rg0x001 -n ${n} --resource-type "${t}"
az resource delete -g rg0x001 -n ${n} --resource-type "${t}"
done
az resource delete -g rg0x001 -n ub0x001_OsDisk_1_b047926cbefc466581f72492df248c7a --resource-type Microsoft.Compute/disks
az resource delete -g rg0x001 -n ub0x002_OsDisk_1_4b30b93f174e4f9c92e8d070f6f26c82 --resource-type Microsoft.Compute/disks
az resource delete -g rg0x001 -n ub0x00158 --resource-type Microsoft.Network/networkInterfaces
az resource delete -g rg0x001 -n ub0x002710 --resource-type Microsoft.Network/networkInterfaces
az resource delete -g rg0x001 -n ub0x001-nsg --resource-type Microsoft.Network/networkSecurityGroups
az resource delete -g rg0x001 -n ub0x002-nsg --resource-type Microsoft.Network/networkSecurityGroups
az resource delete -g rg0x001 -n ub0x001-ip --resource-type Microsoft.Network/publicIPAddresses
az resource delete -g rg0x001 -n ub0x002-ip --resource-type Microsoft.Network/publicIPAddresses