Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Use PowerShell to find and delete empty resource groups in all Azure subscriptions

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

In many cases, we forget to delete Azure resource groups when we are done with them, so I created the following PowerShell script to help clean them up. It applies to all account subscriptions. This script is useful if you have a lot of people in your account managing different Azure Resource but not cleaning up empty resource groups themselves.

# Login to Azure accountLogin-AzureRmAccount # GlobalLogin-AzureRmAccount-Environment AzureChinaCloud # 21V#Get list of Azure Subscription ID's$Subs = (get-AzureRMSubscription) .ID # Loop through the subscriptions to find all empty Resource Groups and store them in $EmptyRGsForEach ($sub in $Subs) {Select-AzureRmSubscription-SubscriptionId $Sub$AllRGs = (Get-AzureRmResourceGroup). ResourceGroupName$UsedRGs = (Get-AzureRMResource | Group-Object ResourceGroupName). Name$EmptyRGs = $AllRGs | Where-Object {$_ notin $UsedRGs} # Loop through the empty Resorce Groups asking if you would like to delete them. And then deletes them.foreach ($EmptyRG in $EmptyRGs) {$Confirmation = Read-Host "Would you like to delete $EmptyRG'(Y) es' or'(N) o'" IF ($Confirmation-eq "y"-or $Confirmation-eq "Yes") {Write-Host "Deleting" $EmptyRG "ResourceGroup" Remove-AzureRmResourceGroup-Name $EmptyRG-Force}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report