Different results when using Powershell vs Graph Explorer

Pfeiffer Andreas - UCI 215 Reputation points
2023-11-06T14:27:08.77+00:00

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 :

https://graph.microsoft.com/v1.0/users/?$select=id,displayName,mail,jobTitle,userType,department,companyName,signInActivity&$top=10

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.
12,318 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,613 questions
0 comments No comments
{count} votes

Accepted answer
  1. Vasil Michev 108.3K Reputation points MVP
    2023-11-06T17:14:30.8133333+00:00

    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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.