I’m trying to connect to Microsoft Graph using a User Managed Identity(UMI). I created the managed identity through the Azure portal, but now need to assign permissions like Users.Read.All and Group.Read.All to this identity using PowerShell so it can access user and group information.
I’ve found a script that uses the AzureAD module but as it is deprecating soon I want to transition to the Microsoft Graph PowerShell module where I need help with the equivalent commands.
Here’s the old script I found:
Connect-AzureAD
$TenantID = "TenantID"
$GraphAppId = "00000003-0000-0000-c000-000000000000"
$NameOfMSI = "my-managed-identity"
$Permissions = @(
"Group.Read.All",
"User.Read.All"
)
$MSI = (Get-AzureADServicePrincipal -Filter "displayName eq '$NameOfMSI'")
Start-Sleep -Seconds 10
$GraphServicePrincipal = Get-AzureADServicePrincipal -Filter "appId eq
'$GraphAppId'"
foreach ($PermissionName in $Permissions) {
$AppRole = $GraphServicePrincipal.AppRoles | Where-Object {
$_.Value -eq $PermissionName -and $_.AllowedMemberTypes -contains
"Application" }
New-AzureAdServiceAppRoleAssignment -ObjectId $MSI.ObjectId
-PrincipalId $MSI.ObjectId -ResourceId $GraphServicePrincipal.ObjectId
-Id $AppRole.Id
}
Can anyone provide guidance or a script to achieve this using the Microsoft Graph PowerShell module?
L S is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.