I'm trying to list unused, unattached, and unassociated resources inside Azure using Azure CLI.
So far, I've got unmanaged disks using the command:
unmanagedDiskNames=$(az disk list -g $rgName --query "[?(managedBy==null)].name" -o tsv)
I've got unattached Network interfaces using the command:
unattachedNicsIds=$(az network nic list -g $rgName --query "[?(virtualMachine==null)].id" -o tsv)
I'm having issued listing Public IPs and Network security groups. Tried to get public IPs using the command (it not worked):
unassociated_publicIPs=$(az network public-ip list -g "Technology-RG" --query "[?(IpConfiguration==null)].id" -o tsv)
Can you help me get unassociated public IPs and NSGs? Thank you.
Solved, the command for listing unassociated public IPs using Azure CLI is:
az network public-ip list -g $rgName --query "[?(ipConfiguration==null)].id" -o tsv
The command for listing unassociated network security groups IPs using Azure CLI is:
az network nsg list -g $rgName --query "[?(subnets==null) && (networkInterfaces==null)].id" -o tsv