Skip to content

/flags/microsoft-graph/get-mguser-property

Get-MgUser -Property: why properties are empty and how to select them

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated
tool
Microsoft Graph PowerShell
command
Get-MgUser
flag
-Property (alias -Select)
default
Graph default set: businessPhones, displayName, givenName, id, jobTitle, mail, mobilePhone, officeLocation, preferredLanguage, surname, userPrincipalName

Get-MgUser -Property DisplayName,AccountEnabled,Department asks Microsoft Graph for specific user properties. By default Graph returns only a limited set: "By default, only a limited set of properties are returned (businessPhones, displayName, givenName, id, jobTitle, mail, mobilePhone, officeLocation, preferredLanguage, surname, and userPrincipalName)." Everything else (AccountEnabled, Department, UsageLocation, CreatedDateTime, SignInActivity…) exists on the returned object but is empty until you request it. -Property maps to the OData $select query option and has the alias -Select.

powershell
Connect-MgGraph -Scopes "User.Read.All"
Get-MgUser -UserId anna@contoso.com -Property DisplayName, UserPrincipalName, AccountEnabled, Department, UsageLocation |
  Format-List DisplayName, UserPrincipalName, AccountEnabled, Department, UsageLocation
Get-MgUser -All -Property Id, DisplayName, AccountEnabled, CreatedDateTime |
  Select-Object DisplayName, AccountEnabled, CreatedDateTime

The parameter in the module

-Property is a string array available in every parameter set of Get-MgUser, with the alias Select. Checked offline in Windows PowerShell 5.1 with Microsoft.Graph.Users 2.41.2:

powershell
Import-Module Microsoft.Graph.Users
$p = (Get-Command Get-MgUser).Parameters['Property']
"Type: " + $p.ParameterType.Name
"Aliases: " + ($p.Aliases -join ', ')
"Sets: " + (($p.ParameterSets.Keys | Sort-Object) -join ', ')
"ExpandProperty type: " + (Get-Command Get-MgUser).Parameters['ExpandProperty'].ParameterType.Name

Output

Type: String[]
Aliases: Select
Sets: __AllParameterSets
ExpandProperty type: String[]

Properties that need -Property

The user resource marks many properties "Requires $select to retrieve" (Graph $select, i.e. -Property in PowerShell):

PropertyNotes
AccountEnabledsign-in allowed or blocked
UsageLocationneeded before assigning licenses
PasswordPoliciesDisablePasswordExpiration, DisableStrongPassword
CreatedDateTime, Department, CompanyName, EmployeeIddirectory attributes for reports
OnPremisesSyncEnabled, OnPremisesImmutableIdhybrid (synced) accounts
SignInActivitylast sign-in; needs AuditLog.Read.All, and limits the page size to 500
Managera relationship: use -ExpandProperty manager, not -Property

Pitfalls

  • Default set is replaced. Once you pass -Property, list every property you want, including DisplayName and UserPrincipalName.
  • Case does not matter, spelling does. Property names follow the Graph user resource; a misspelled name makes the request fail with an error from the service.
  • Relationships. Manager, memberOf and similar are relationships, read with -ExpandProperty or separate cmdlets.
  • SignInActivity. Last sign-in data needs extra permissions and licensing; see last sign-in date.
  • All pages. -Property does not change paging; add -All for more than 100 users (Get-MgUser -All).

FAQ

Why is AccountEnabled (or Department, or UsageLocation) empty in Get-MgUser output?

Microsoft Graph returns only a limited default set of user properties. Every other property comes back empty unless you ask for it: Get-MgUser -UserId ID -Property AccountEnabled,Department,UsageLocation.

Does -Property replace the default properties?

Yes. With -Property, Graph returns only the properties you list (plus id), so include DisplayName and UserPrincipalName yourself if you need them.

Why does Select-Object Department still show nothing?

Select-Object only picks from what the cmdlet received. Ask the service for the property with -Property first, then select or format it.

Sources