You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: ensure defender roles and deployments are removed (#462)
# Pull Request
## Description
Fix a bug where defender plans, orphaned role assignments, and
deployments are not checked if the subscription does not contain any
resource groups.
## License
By submitting this pull request, I confirm that my contribution is made
under the terms of the projects associated license.
Write-ToConsoleLog"Retaining resource group as it matches the pattern '$pattern': $($resourceGroup.name) in subscription: $($subscription.Name) (ID: $($subscription.Id))"-NoNewLine
Write-ToConsoleLog"Retaining resource group as it matches the pattern '$pattern': $($resourceGroup.name) in subscription: $($subscription.Name) (ID: $($subscription.Id))"-NoNewLine
Write-ToConsoleLog"Deleting resource group for subscription: $($subscription.Name) (ID: $($subscription.Id)), resource group: $($ResourceGroupName)"-NoNewLine
1078
-
$result=$null
1079
-
if($using:PlanMode) {
1080
-
Write-ToConsoleLog`
1081
-
"Deleting resource group for subscription: $($subscription.Name) (ID: $($subscription.Id)), resource group: $($ResourceGroupName)",`
1082
-
"Would run: az group delete --name $ResourceGroupName --subscription $($subscription.Id) --yes"`
1083
-
-IsPlan -LogFilePath $using:TempLogFileForPlan
1084
-
} else {
1085
-
$result= az group delete --name $ResourceGroupName--subscription $subscription.Id--yes 2>&1
1086
-
}
1075
+
Write-ToConsoleLog"Deleting resource group for subscription: $($subscription.Name) (ID: $($subscription.Id)), resource group: $($ResourceGroupName)"-NoNewLine
1076
+
$result=$null
1077
+
if($using:PlanMode) {
1078
+
Write-ToConsoleLog`
1079
+
"Deleting resource group for subscription: $($subscription.Name) (ID: $($subscription.Id)), resource group: $($ResourceGroupName)",`
1080
+
"Would run: az group delete --name $ResourceGroupName --subscription $($subscription.Id) --yes"`
1081
+
-IsPlan -LogFilePath $using:TempLogFileForPlan
1082
+
} else {
1083
+
$result= az group delete --name $ResourceGroupName--subscription $subscription.Id--yes 2>&1
1084
+
}
1087
1085
1088
-
if (!$result) {
1089
-
Write-ToConsoleLog"Deleted resource group for subscription: $($subscription.Name) (ID: $($subscription.Id)), resource group: $($ResourceGroupName)"-NoNewLine
1086
+
if (!$result) {
1087
+
Write-ToConsoleLog"Deleted resource group for subscription: $($subscription.Name) (ID: $($subscription.Id)), resource group: $($ResourceGroupName)"-NoNewLine
1088
+
} else {
1089
+
Write-ToConsoleLog"Delete resource group failed for subscription: $($subscription.Name) (ID: $($subscription.Id)), resource group: $($ResourceGroupName)"-NoNewLine
1090
+
Write-ToConsoleLog"It will be retried once the other resource groups in the subscription have reported their status."-NoNewLine
1091
+
$retries=$using:resourceGroupsToRetry
1092
+
$retries.Add($_)
1093
+
}
1094
+
} -ThrottleLimit $using:ThrottleLimit
1095
+
1096
+
if($resourceGroupsToRetry.Count-gt0) {
1097
+
Write-ToConsoleLog"Some resource groups failed to delete and will be retried in subscription: $($subscription.Name) (ID: $($subscription.Id))"-NoNewLine
Write-ToConsoleLog"Delete resource group failed for subscription: $($subscription.Name) (ID: $($subscription.Id)), resource group: $($ResourceGroupName)"-NoNewLine
1092
-
Write-ToConsoleLog"It will be retried once the other resource groups in the subscription have reported their status."-NoNewLine
1093
-
$retries=$using:resourceGroupsToRetry
1094
-
$retries.Add($_)
1101
+
Write-ToConsoleLog"All resource groups deleted successfully in subscription: $($subscription.Name) (ID: $($subscription.Id))."-NoNewLine
1095
1102
}
1096
-
} -ThrottleLimit $using:ThrottleLimit
1097
-
1098
-
if($resourceGroupsToRetry.Count-gt0) {
1099
-
Write-ToConsoleLog"Some resource groups failed to delete and will be retried in subscription: $($subscription.Name) (ID: $($subscription.Id))"-NoNewLine
0 commit comments