Different results when using Powershell vs Graph Explorer

Pfeiffer Andreas - UCI 20 Reputation points

Dear all,

I try to get the same result set of a graph api call, using on one hand the graph api explorer ( https://developer.microsoft.com/en-us/graph/graph-explorer ) and on the other hand when I execute the cmdlet Get-MgUser . This is especially the case for the properties userType, department and companyName (there maybe others !).

The url called in the explorer is the following :


The (summarized) result I get is :

User's image

But when I execute the following command in powershell (graph version 2.8.0) :

$users = Get-MgUser -Top 10

$users | Format-List -Property Id,DisplayName,Mail,JobTitle,UserType,Department,CompanyName,SignInActivity

I get the following :
User's image

Why this difference ? Is there something I missed in my powershell command line ? How can I get the userType, companyName and Department with my powershell script ? (note that the scope is set on the app level and I connect with a certificate)

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
9,109 questions
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
1,553 questions
0 comments No comments
{count} votes

Accepted answer
  1. Vasil Michev 85,556 Reputation points MVP

    The Graph SDK for PowerShell cmdlets will by default return only a handful of properties. In your scenario, you need to request the properties, via the -Property parameter first:

    Get-MgUser -Top 10 -Property Id,DisplayName,Mail,JobTitle,UserType,Department,CompanyName,SignInActivity | select Id,DisplayName,Mail,JobTitle,UserType,Department,CompanyName,SignInActivity

    In addition, SignInActivity needs to be expanded, i.e.:

    Get-MgUser -Top 10 -Property Id,DisplayName,Mail,JobTitle,UserType,Department,CompanyName,SignInActivity | select Id,DisplayName,Mail,JobTitle,UserType,Department,CompanyName,@{n="LastLogin";e={$_.signInActivity.lastSignInDateTime}}

    Alternatively, you can use the Beta module/endpoint, which returns all properties by default.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful