Created
May 20, 2020 01:58
-
-
Save jesseloudon/5ccc96c9e13576d23a090420b65b82ec to your computer and use it in GitHub Desktop.
Find and remove Azure RBAC Role Assignments of 'Unknown' Type.
This file contains 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
#AuthN | |
Connect-AzAccount | |
#Set Your Subscription ID | |
Set-AzContext -SubscriptionId "XXXXX-XXXXX-XXXXX-XXXXXX-XXXXXX" | |
#Common Variables | |
$FILEPATH = "C:\Temp" | |
$FILENAME = "AzureRoleAssignmentsToRemove.csv" | |
$SUBNAME = "SUBSCRIPTIONNAME" | |
$OBJTYPE = "Unknown" | |
#Find and Export-to-CSV Azure RBAC Role Assignments of 'Unknown' Type | |
$raunknown = Get-AzRoleAssignment | Where-Object {$_.ObjectType.Equals($OBJTYPE)} | Export-Csv "$FILEPATH\$SUBNAME-$FILENAME" -NoTypeInformation | |
#Import-from-CSV and Remove each Azure Role Assignment | |
$RASTOREMOVE = Import-CSV "$FILEPATH\$SUBNAME-$FILENAME" | |
$RASTOREMOVE|ForEach-Object { | |
$object = $_.ObjectId | |
$roledef = $_.RoleDefinitionName | |
$rolescope = $_.Scope | |
Remove-AzRoleAssignment -ObjectId $object -RoleDefinitionName $roledef -Scope $rolescope | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment