资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

使用PowerShell查找和删除所有Azure订阅中的空资源组

在很多情况下,当我们使用完Azure资源组之后总是忘记删除它们,所以我创建了下面的PowerShell脚本来帮助清理它们。它适用于所有的账户订阅。如果您的账户中有很多人在管理不同的Azure Resource但其并而不是自己清理空的资源组,那么这个脚本就很有用使用PowerShell查找和删除所有Azure订阅中的空资源组

创新互联专注于博州网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供博州营销型网站建设,博州网站制作、博州网页设计、博州网站官网定制、重庆小程序开发服务,打造博州网络公司原创品牌,更为您提供博州网站排名全网营销落地服务。

#Log in to Azure account
Login-AzureRmAccount #Global
Login-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 $EmptyRGs
ForEach ($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 "Resource Group"
Remove-AzureRmResourceGroup -Name $EmptyRG -Force
}
}
}

分享文章:使用PowerShell查找和删除所有Azure订阅中的空资源组
标题网址:http://cdkjz.cn/article/jeejpp.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220