Export guides / Microsoft 365 and Entra ID
How to export Microsoft Entra consent grants with PowerShell for an AI use review
Which apps people (or an admin, for everyone) allowed into mail, files or calendars, with the permissions granted.
Consent grants show the access an AI app was given: for example a meeting recorder that can read every user's calendar, or an assistant with permission to read mail. The script only reads; it changes nothing in the tenant.
- Who can do it
- An admin with a read role such as Global Reader or Directory Readers (Microsoft also lists Cloud Application Administrator and Application Administrator). The first time, an admin may need to approve the Microsoft Graph Command Line Tools app.
- Licence or plan
- No extra licence. The Microsoft Graph PowerShell module is free.
- Date range
- No date range: the export lists every grant that is in force today, however long ago it was given.
Steps
Menus change from time to time; paths below are where the option is typically found.
- On a Windows PC, open PowerShell. If the Microsoft Graph module isn't installed, run
Install-Module Microsoft.Graph -Scope CurrentUseronce. - Copy the script below into PowerShell and run it. Sign in when the browser window opens and accept the read-only Directory.Read.All permission.
- Wait for it to finish. It writes
consent-grants.csvin the current folder and signs out. - Upload
consent-grants.csvto the review in Vigilo as it is.
Read-only script
Connect-MgGraph -Scopes "Directory.Read.All"
$names = @{}
Get-MgServicePrincipal -All -Property Id,DisplayName | ForEach-Object { $names[$_.Id] = $_.DisplayName }
$upns = @{}
Get-MgOauth2PermissionGrant -All | ForEach-Object {
if ($_.PrincipalId -and -not $upns.ContainsKey($_.PrincipalId)) {
$upns[$_.PrincipalId] = (Get-MgUser -UserId $_.PrincipalId -Property UserPrincipalName -ErrorAction SilentlyContinue).UserPrincipalName
}
[pscustomobject]@{
ClientId = $_.ClientId
ClientDisplayName = $names[$_.ClientId]
ConsentType = $_.ConsentType
PrincipalUserPrincipalName = if ($_.PrincipalId) { $upns[$_.PrincipalId] } else { "" }
ResourceDisplayName = $names[$_.ResourceId]
Scope = $_.Scope
}
} | Export-Csv -Path .\consent-grants.csv -NoTypeInformation -Encoding UTF8
Disconnect-MgGraph
Keeping the file small
- The file has one row per grant and is normally small.
- Each upload can be up to 25 MB. Where the export lets you choose, include only the review period and the columns this guide lists.
What Vigilo uses from the file
The app name, whether the consent was for everyone (AllPrincipals, an admin consent) or for one person, that person's username, and the permissions (scopes). Broad or write access and admin consent become checks ACC-01 and ACC-04.
Privacy
What the file holds: The usernames (UPNs) of people who consented to apps.
Vigilo replaces every person in a user, email or username column with a pseudonymous label such as User-3f9a1c before analysis, never reads IP address columns, and never sends raw rows to an AI model. Tell staff about the review before you export their data, in the way privacy and workplace surveillance laws require where you are.
Last checked: November 2026. Source: Microsoft Learn: List oauth2PermissionGrants (permissions and roles).