Last active
June 19, 2022 01:33
-
-
Save damienpontifex/74d23e48c99f20b70ac5c8b527706b47 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.DESCRIPTION | |
An example runbook which gets all the ARM resources using the Managed Identity | |
.NOTES | |
AUTHOR: Azure Automation Team | |
LASTEDIT: Oct 26, 2021 | |
#> | |
try | |
{ | |
"Logging in to Azure..." | |
Connect-AzAccount -Identity | |
} | |
catch { | |
Write-Error -Message $_.Exception | |
throw $_.Exception | |
} | |
$ResourceGroups = Get-AzResourceGroup | |
foreach ($ResourceGroup in $ResourceGroups) | |
{ | |
$Tags = $ResourceGroup.Tags | |
if (($Tags -ne $null) -and ($Tags.ContainsKey("AutoDelete")) -and ($Tags["AutoDelete"] -eq "false")) | |
{ | |
Write-Output "Skipping deletion of resource group $($ResourceGroup.ResourceGroupName) because AutoDelete tag is: '$AutoDelete'" | |
} | |
else | |
{ | |
Write-Output "Will delete resource group $($ResourceGroup.ResourceGroupName)" | |
# Remove-AzResourceGroup -Name $ResourceGroup.ResourceGroupName -Force -AsJob | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment