Skip to content

Commit 4582fd4

Browse files
fix: refactor logic (#458)
## Description Refactor Copilot logic... ## License By submitting this pull request, I confirm that my contribution is made under the terms of the projects associated license.
1 parent 87bd8d9 commit 4582fd4

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed

src/ALZ/Public/Remove-PlatformLandingZone.ps1

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ function Remove-PlatformLandingZone {
717717
}
718718

719719
# Delete deployments from target management groups that are not being deleted
720-
if($managementGroupsFound.Count -ne 0 -and -not $SkipDeploymentDeletion) {
720+
if($managementGroupsFound.Count -ne 0 -and -not $SkipDeploymentDeletion -and -not $DeleteTargetManagementGroups) {
721721
$managementGroupsFound | ForEach-Object -Parallel {
722722
$managementGroupId = $_.Name
723723
$managementGroupDisplayName = $_.DisplayName
@@ -727,22 +727,20 @@ function Remove-PlatformLandingZone {
727727
$funcRemoveDeploymentsForScope = $using:funcRemoveDeploymentsForScope
728728
${function:Remove-DeploymentsForScope} = $funcRemoveDeploymentsForScope
729729

730-
# Only delete deployments if this management group is not being deleted
731-
if(-not $deleteTargetManagementGroups) {
732-
Remove-DeploymentsForScope `
733-
-ScopeType "management group" `
734-
-ScopeNameForLogs "$managementGroupId ($managementGroupDisplayName)" `
735-
-ScopeId $managementGroupId `
736-
-ThrottleLimit $using:ThrottleLimit `
737-
-PlanMode:$using:PlanMode
738-
} else {
739-
Write-ToConsoleLog "Skipping deployment deletion for management group: $managementGroupId ($managementGroupDisplayName) as it is being deleted" -NoNewLine
740-
}
730+
Remove-DeploymentsForScope `
731+
-ScopeType "management group" `
732+
-ScopeNameForLogs "$managementGroupId ($managementGroupDisplayName)" `
733+
-ScopeId $managementGroupId `
734+
-ThrottleLimit $using:ThrottleLimit `
735+
-PlanMode:$using:PlanMode
736+
741737
} -ThrottleLimit $ThrottleLimit
738+
} else {
739+
Write-ToConsoleLog "Skipping deployment deletion for management groups" -NoNewLine
742740
}
743741

744742
# Delete orphaned role assignments from target management groups that are not being deleted
745-
if($managementGroupsFound.Count -ne 0 -and -not $SkipOrphanedRoleAssignmentDeletion) {
743+
if($managementGroupsFound.Count -ne 0 -and -not $SkipOrphanedRoleAssignmentDeletion -and -not $DeleteTargetManagementGroups) {
746744
$managementGroupsFound | ForEach-Object -Parallel {
747745
$managementGroupId = $_.Name
748746
$managementGroupDisplayName = $_.DisplayName
@@ -752,20 +750,16 @@ function Remove-PlatformLandingZone {
752750
$funcRemoveOrphanedRoleAssignmentsForScope = $using:funcRemoveOrphanedRoleAssignmentsForScope
753751
${function:Remove-OrphanedRoleAssignmentsForScope} = $funcRemoveOrphanedRoleAssignmentsForScope
754752

755-
# Only delete role assignments if this management group is not being deleted
756-
if(-not $deleteTargetManagementGroups) {
757-
Remove-OrphanedRoleAssignmentsForScope `
758-
-ScopeType "management group" `
759-
-ScopeNameForLogs "$managementGroupId ($managementGroupDisplayName)" `
760-
-ScopeId $managementGroupId `
761-
-ThrottleLimit $using:ThrottleLimit `
762-
-PlanMode:$using:PlanMode
763-
} else {
764-
Write-ToConsoleLog "Skipping orphaned role assignment deletion for management group: $managementGroupId ($managementGroupDisplayName) as it is being deleted" -NoNewLine
765-
}
753+
Remove-OrphanedRoleAssignmentsForScope `
754+
-ScopeType "management group" `
755+
-ScopeNameForLogs "$managementGroupId ($managementGroupDisplayName)" `
756+
-ScopeId $managementGroupId `
757+
-ThrottleLimit $using:ThrottleLimit `
758+
-PlanMode:$using:PlanMode
759+
766760
} -ThrottleLimit $ThrottleLimit
767-
} elseif($managementGroupsFound.Count -ne 0) {
768-
Write-ToConsoleLog "Skipping orphaned role assignment deletion for all management groups as requested" -NoNewLine
761+
} else {
762+
Write-ToConsoleLog "Skipping orphaned role assignment deletion for management groups" -NoNewLine
769763
}
770764
}
771765

0 commit comments

Comments
 (0)