/errors/microsoft-graph/get-mguser-parameter-set-cannot-be-resolved
Get-MgUser : Parameter set cannot be resolved using the specified named parameters.
- tool
- Microsoft Graph PowerShell
- exit code
- 1
- versions
- Microsoft.Graph.Users 2.41.2, Windows PowerShell 5.1, PowerShell 7
- os
- windows, linux, macos
Get-MgUser : Parameter set cannot be resolved using the specified named parameters. means the parameters you passed belong to different parameter sets of Get-MgUser, so PowerShell cannot choose one. The usual mix-up is -UserId (read one user) together with -Filter, -Search, -All or -Top (list users). Use one form or the other:
# One user, by object ID or UPN
Get-MgUser -UserId 'jdoe@contoso.com' -Property DisplayName, Department
# A list, with a filter
Get-MgUser -Filter "department eq 'Sales'" -All -Property DisplayName, DepartmentThe binding error is raised before any request is sent, so it appears even without Connect-MgGraph.
Reproduce it
Microsoft.Graph.Users 2.41.2, Windows PowerShell 5.1, no connection:
Import-Module Microsoft.Graph.Users
try {
Get-MgUser -UserId 'jdoe@contoso.com' -Filter "department eq 'Sales'" -ErrorAction Stop
} catch {
$_.Exception.Message
$_.FullyQualifiedErrorId
}
(Get-Command Get-MgUser).ParameterSets | ForEach-Object {
$names = $_.Parameters.Name | Where-Object { $_ -in 'UserId','InputObject','Filter','Search','All','Top','ConsistencyLevel','Property' }
$_.Name + ': ' + ($names -join ', ')
}Output
Parameter set cannot be resolved using the specified named parameters. AmbiguousParameterSet,Get-MgUser List: Property, Filter, Search, Top, ConsistencyLevel, All Get: UserId, Property GetViaIdentity: InputObject, Property
The three parameter sets
| Parameter set | Identifies users with | Typical parameters |
|---|---|---|
| List | nothing (returns a collection) | -Filter, -Search, -All, -Top, -ConsistencyLevel, -CountVariable, -Property |
| Get | -UserId (object ID or userPrincipalName) | -Property, -ExpandProperty |
| GetViaIdentity | -InputObject (pipeline) | -Property, -ExpandProperty |
The same pattern applies to most Microsoft Graph PowerShell cmdlets: Get-MgGroup -GroupId versus Get-MgGroup -Filter, Get-MgDevice -DeviceId versus Get-MgDevice -Filter.
Look up a user by an attribute other than ID or UPN
-UserId accepts only the object ID or the userPrincipalName. To find a user by mail, employee ID or display name, use the List set with -Filter:
Get-MgUser -Filter "mail eq 'john.doe@contoso.com'"
Get-MgUser -Filter "employeeId eq '10442'" -Property DisplayName, EmployeeId
Get-MgUser -Search '"displayName:John"' -ConsistencyLevel eventual -CountVariable nFilters on some properties and all -Search queries need -ConsistencyLevel eventual; see Get-MgUser -ConsistencyLevel eventual.