Skip to content

Commit

Permalink
Get all data - add -all for needed commands
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelmsonne committed Oct 25, 2024
1 parent cbcd012 commit 245d298
Show file tree
Hide file tree
Showing 2 changed files with 982 additions and 1,005 deletions.
14 changes: 7 additions & 7 deletions src/Globals.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ function Get-ScriptDirectory
function Get-ManagedIdentityCount
{
# Get data to global data to keep
$global:managedIdentities = Get-MgServicePrincipal -Filter "servicePrincipalType eq 'ManagedIdentity'"
$global:managedIdentities = Get-MgServicePrincipal -Filter "servicePrincipalType eq 'ManagedIdentity'" -All

# Return data
return $global:managedIdentities.Count
Expand Down Expand Up @@ -377,7 +377,7 @@ function Get-CurrentAppRoleAssignments
Write-Log -Level INFO -Message "Getting permissions for Managed Identity with Id: '$ManagedIdentityID'"

# Get current role assignments
$currentAppRoles = Get-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $ManagedIdentityID -ErrorAction Stop
$currentAppRoles = Get-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $ManagedIdentityID -All -ErrorAction Stop

# Of any roles assigned
if ($currentAppRoles)
Expand Down Expand Up @@ -484,7 +484,7 @@ function Add-ServicePrincipalPermission
# Log
Write-Log -Level INFO -Message "Removing existing permissions because clear existing permissions is set"

$AssignedPermissions = Get-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $ManagedIdentityID
$AssignedPermissions = Get-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $ManagedIdentityID -All

if ($AssignedPermissions.Count -eq 0)
{
Expand Down Expand Up @@ -554,7 +554,7 @@ function Add-ServicePrincipalPermission
# If exists
if ($AppRole)
{
$existingAppRole = Get-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $ManagedIdentityID | Where-Object { $_.ResourceId -eq $AppGraph.Id -and $_.AppRoleId -eq $AppRole.Id }
$existingAppRole = Get-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $ManagedIdentityID -All | Where-Object { $_.ResourceId -eq $AppGraph.Id -and $_.AppRoleId -eq $AppRole.Id }
if ($existingAppRole)
{
# Log
Expand All @@ -568,7 +568,7 @@ function Add-ServicePrincipalPermission
New-MgServicePrincipalAppRoleAssignment -PrincipalId $ManagedIdentityID -ServicePrincipalId $ManagedIdentityID -ResourceId $AppGraph.Id -AppRoleId $AppRole.Id -ErrorAction Stop

# Validate
$existingAppRole = Get-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $ManagedIdentityID | Where-Object { $_.ResourceId -eq $AppGraph.Id -and $_.AppRoleId -eq $AppRole.Id }
$existingAppRole = Get-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $ManagedIdentityID -All | Where-Object { $_.ResourceId -eq $AppGraph.Id -and $_.AppRoleId -eq $AppRole.Id }
if ($existingAppRole)
{
# Log
Expand Down Expand Up @@ -665,7 +665,7 @@ function Remove-ServicePrincipalPermission
Write-Log -Level INFO -Message "Permissions to remove: $Perms"

# Get the current API permissions assigned to the managed identity
$currentPermissions = Get-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $ManagedIdentityID
$currentPermissions = Get-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $ManagedIdentityID -All

# Get all available permissions for the service principal
$allPermissions = @{ }
Expand Down Expand Up @@ -749,7 +749,7 @@ function Remove-AllServicePrincipalPermissions
Write-Log -Level INFO -Message "Managed Identity ObjectID: '$ManagedIdentityID'"

# Get the current API permissions assigned to the managed identity
$currentPermissions = Get-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $ManagedIdentityID
$currentPermissions = Get-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $ManagedIdentityID -All

if ($currentPermissions.Count -eq 0)
{
Expand Down
Loading

0 comments on commit 245d298

Please sign in to comment.