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
@@ -616,6 +629,8 @@ function Remove-PlatformLandingZone {
616
629
Write-ToConsoleLog"Skipping orphaned role assignment deletion for management group: $managementGroupId ($managementGroupDisplayName) as it is being deleted"-NoNewLine
617
630
}
618
631
} -ThrottleLimit $throttleLimit
632
+
} elseif($managementGroupsFound.Count-ne0) {
633
+
Write-ToConsoleLog"Skipping orphaned role assignment deletion for all management groups as requested"-NoNewLine
619
634
}
620
635
}
621
636
@@ -805,36 +820,40 @@ function Remove-PlatformLandingZone {
805
820
Write-ToConsoleLog"Skipping subscription level deployment deletion in subscription: $($subscription.Name) (ID: $($subscription.Id))"-NoNewLine
806
821
}
807
822
808
-
Write-ToConsoleLog"Checking for orphaned role assignments to delete in subscription: $($subscription.Name) (ID: $($subscription.Id))"-NoNewLine
809
-
$roleAssignments= (az role assignment list --subscription $subscription.Id--query "[?principalName==''].{id:id,principalId:principalId,roleDefinitionName:roleDefinitionName}"-o json) |ConvertFrom-Json
Write-ToConsoleLog"Checking for orphaned role assignments to delete in subscription: $($subscription.Name) (ID: $($subscription.Id))"-NoNewLine
825
+
$roleAssignments= (az role assignment list --subscription $subscription.Id--query "[?principalName==''].{id:id,principalId:principalId,roleDefinitionName:roleDefinitionName}"-o json) |ConvertFrom-Json
810
826
811
-
if ($roleAssignments-and$roleAssignments.Count-gt0) {
812
-
Write-ToConsoleLog"Found $($roleAssignments.Count) orphaned role assignment(s) in subscription: $($subscription.Name) (ID: $($subscription.Id))"-NoNewLine
827
+
if ($roleAssignments-and$roleAssignments.Count-gt0) {
828
+
Write-ToConsoleLog"Found $($roleAssignments.Count) orphaned role assignment(s) in subscription: $($subscription.Name) (ID: $($subscription.Id))"-NoNewLine
Write-ToConsoleLog"Deleting orphaned role assignment: $($roleAssignment.roleDefinitionName) for principal: $($roleAssignment.principalId) from subscription: $($subscription.Name) (ID: $($subscription.Id))"-NoNewLine
821
-
$result=$null
822
-
if($using:planMode) {
823
-
Write-ToConsoleLog"(Plan Mode) Would run: az role assignment delete --ids $($roleAssignment.id)"-NoNewLine -Color Gray
824
-
} else {
825
-
$result= az role assignment delete --ids $roleAssignment.id2>&1
826
-
}
836
+
Write-ToConsoleLog"Deleting orphaned role assignment: $($roleAssignment.roleDefinitionName) for principal: $($roleAssignment.principalId) from subscription: $($subscription.Name) (ID: $($subscription.Id))"-NoNewLine
837
+
$result=$null
838
+
if($using:planMode) {
839
+
Write-ToConsoleLog"(Plan Mode) Would run: az role assignment delete --ids $($roleAssignment.id)"-NoNewLine -Color Gray
840
+
} else {
841
+
$result= az role assignment delete --ids $roleAssignment.id2>&1
842
+
}
827
843
828
-
if (!$result) {
829
-
Write-ToConsoleLog"Deleted orphaned role assignment: $($roleAssignment.roleDefinitionName) from subscription: $($subscription.Name) (ID: $($subscription.Id))"-NoNewLine
830
-
} else {
831
-
Write-ToConsoleLog"Failed to delete orphaned role assignment: $($roleAssignment.roleDefinitionName) from subscription: $($subscription.Name) (ID: $($subscription.Id))"-IsWarning -NoNewLine
832
-
}
833
-
} -ThrottleLimit $using:throttleLimit
844
+
if (!$result) {
845
+
Write-ToConsoleLog"Deleted orphaned role assignment: $($roleAssignment.roleDefinitionName) from subscription: $($subscription.Name) (ID: $($subscription.Id))"-NoNewLine
846
+
} else {
847
+
Write-ToConsoleLog"Failed to delete orphaned role assignment: $($roleAssignment.roleDefinitionName) from subscription: $($subscription.Name) (ID: $($subscription.Id))"-IsWarning -NoNewLine
848
+
}
849
+
} -ThrottleLimit $using:throttleLimit
834
850
835
-
Write-ToConsoleLog"All orphaned role assignments processed in subscription: $($subscription.Name) (ID: $($subscription.Id))"-NoNewLine
851
+
Write-ToConsoleLog"All orphaned role assignments processed in subscription: $($subscription.Name) (ID: $($subscription.Id))"-NoNewLine
852
+
} else {
853
+
Write-ToConsoleLog"No orphaned role assignments found in subscription: $($subscription.Name) (ID: $($subscription.Id)), skipping."-NoNewLine
854
+
}
836
855
} else {
837
-
Write-ToConsoleLog"No orphaned role assignments found in subscription: $($subscription.Name) (ID: $($subscription.Id)), skipping."-NoNewLine
856
+
Write-ToConsoleLog"Skipping orphaned role assignment deletion in subscription: $($subscription.Name) (ID: $($subscription.Id))"-NoNewLine
0 commit comments