Microsoft Graph (Entra) Settings
Last updated
http://localhost/test/FetchAllEntraGroups# Variables
$TenantId = "<TENANT_ID>"
$ClientId = "<APP_ID>"
$ClientSecret = "<CLIENT_SECRET_VALUE>"
$GroupName = "<SECURITY_GROUP_NAME>"
# Get OAuth token
$Body = @{
client_id = $ClientId
scope = "https://graph.microsoft.com/.default"
client_secret = $ClientSecret
grant_type = "client_credentials"
}
$TokenResponse = Invoke-RestMethod `
-Method Post `
-Uri "https://login.microsoftonline.com/$TenantId/oauth2/v2.0/token" `
-Body $Body `
-ContentType "application/x-www-form-urlencoded"
$AccessToken = $TokenResponse.access_token
$Headers = @{
Authorization = "Bearer $AccessToken"
}
# Search group
$GroupSearchUri = "https://graph.microsoft.com/v1.0/groups?`$filter=displayName eq '$GroupName'"
$GroupResponse = Invoke-RestMethod `
-Method Get `
-Uri $GroupSearchUri `
-Headers $Headers
$GroupId = $GroupResponse.value[0].id
Write-Host "Group ID: $GroupId"
# Get group members
$MembersUri = "https://graph.microsoft.com/v1.0/groups/$GroupId/transitiveMembers?`$select=displayName,userPrincipalName,mail"
$MembersResponse = Invoke-RestMethod `
-Method Get `
-Uri $MembersUri `
-Headers $Headers
$MembersResponse.value |
Select-Object displayName,userPrincipalName,mail |
Format-Table -AutoSize