- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 } }
- Related Articles
- How to delete the Azure Resource Group using PowerShell?
- How to get the Azure resource group using Azure CLI in PowerShell?
- How to retrieve the Azure VM resource group using PowerShell?
- How to create a new Azure resource group using PowerShell?
- How to apply a tag to the azure resource group using PowerShell?
- How to get the azure resources from the resource group using PowerShell?
- How to check if the file is empty using PowerShell?
- How to get the applied azure resource tags using PowerShell?
- How to delete all the tags of the azure resource using PowerShell?
- How to check if PSCustomObject is empty in PowerShell?
- How to check an array is empty or not using jQuery?
- Python program to check if the string is empty or not
- How to check which Azure account is logged in using PowerShell?
- How to check Azure VM Power state using PowerShell?
- MySQL query to check if database is empty or not?

Advertisements