
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check if Azure Resource Group is Empty Using PowerShell
To check if the resource group is empty or not we need to check if the resource group contains any resources.
For this example, We have a resource group name called the TestRG and we need to check if it is empty.
Example
$resources = Get-AzResource -ResourceGroupName TestRG if($resources){"Resource group is not empty"} else{"Resource group is empty"}
Output
Resource group is empty
To check if the resource groups in the particular subscription are empty or not, use the below code.
Output
Connect-AZAccount Set-AzContext -SubscriptionName 'Your Subscription Name' $rgs = Get-AzResourceGroup Write-Output "Empty Resource Groups" foreach($rg in $rgs.ResourceGroupName){ $resources = Get-AzResource -ResourceGroupName $rg if(!($resources)){ $rg } }
Advertisements