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.