Skip to content
M365-04 Field-tested

Graph SDK cmdlets fail with AggregateException

Graph PowerShell cmdlets throw an unhelpful AggregateException. Call the endpoints directly with Invoke-MgGraphRequest.

Symptom

Get-Mg* cmdlets fail with System.AggregateException (“One or more errors occurred”), often after a module update or when several Graph modules are installed at different versions.

Fix: depend on one module only

Use only Microsoft.Graph.Authentication and call the API directly:

Import-Module Microsoft.Graph.Authentication
Connect-MgGraph -Scopes "User.Read.All"

$users = @()
$uri = "https://graph.microsoft.com/v1.0/users?`$select=id,userPrincipalName,accountEnabled"
do {
  $page  = Invoke-MgGraphRequest -Method GET -Uri $uri
  $users += $page.value
  $uri   = $page.'@odata.nextLink'
} while ($uri)

This avoids version mismatches between the dozens of Graph submodules, and it works the same everywhere.

See the real error

When something does fail, the useful message is in the innermost exception:

try { ... } catch {
  $e = $_.Exception
  while ($e.InnerException) { $e = $e.InnerException }
  Write-Error $e.Message
}

See also M365-07 for the script standard we apply to client tenants.

Seeing this in your environment?

We can check for this, and everything around it, as part of an audit.

Ask us about M365-04

Find out what's really going on in your tenant.

Tell us what you run and what's worrying you. We'll recommend the right audit, and tell you honestly if you don't need one.