-2

I am trying to get a list of users' emails from o365 using graph API. I am able to get the complete list using following API https://graph.microsoft.com/v1.0/users?$select=mail

The problem is o365 contains multiple domains and I want to list users from specific domains only. Is there a way to do this?

Squti
  • 4,171
  • 3
  • 10
  • 21

3 Answers3

0

You do not specify a domain. The service will determine the domain based on the access token that is provided with the request.

Paul Schaeflein
  • 607
  • 3
  • 11
  • 1
    Thanks Paul. Can I make any changes in app permission of application registered in azure active directory to get the expected list of emails? – Randhir Sharma Jan 07 '20 at 06:47
0

You can fetch this using an advanced Graph query filter. Please refer microsoft documentation https://learn.microsoft.com/en-us/graph/aad-advanced-queries

Use the header ConsistencyLevel and its value as eventual and pass the filter endsWith(mail,' your domain name') in your API call. Refere the image

0

Sadly the endsWith query-filter ist not supported yet. But there is a way around it, it's not so elegant since we're first getting all the users and then reselect the ones with the specific domain:

Connect-MgGraph -Scopes "User.Read.All"
    
$DisabledDomainUsers = Get-MgUser -Filter 'accountEnabled eq false' -All | Where-Object {$_.Mail -like "*@domain.ch"}

The following Modules are needed to use the commands above:

Install-Module Microsoft.Graph -Scope CurrentUser
Install-Module Microsoft.Graph.Users -Scope CurrentUser
V4LC0
  • 1