Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
How to check if the Azure resource group is empty or not 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
