How to fetch country and locale for enterprise users from Graph API?

POOJA CHAUDHARY 0 Reputation points Microsoft Employee
2024-07-22T10:31:49.5733333+00:00

Is there any way to retrieve the country and locale of enterprise users through Graph API?

Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Karelpelck 710 Reputation points
    2024-07-22T11:33:51.7033333+00:00

    To get the locale and country for multiple Microsoft 365 users using the Microsoft Graph API, you can follow these steps:

    1. Set Up Your Environment:
      • Install the Microsoft Graph PowerShell SDK if you haven’t already:
             Install-Module Microsoft.Graph.beta -Scope CurrentUser
             
        
    2. Authenticate:
      • Authenticate to Microsoft Graph:
             Connect-MgGraph -Scopes "User.Read.All"
        
    3. Retrieve User Information:
      • Use the following PowerShell script to get the locale and country for multiple users:
             # Get all users
             $users = Get-MgBetaUser -All
             # Loop through each user to get their locale and country
             foreach ($user in $users) {
                 $userSettings = Get-MgBetaUserSettingsRegionalAndLanguageSetting -UserId $user.Id
                 $locale = $userSettings.defaultDisplayLanguage.locale
                 $country = $user.country
                 
                 # Output user information
                 Write-Output "User: $($user.DisplayName), Locale: $locale, Country: $country"
             }
             
        

    This script retrieves all users and then loops through each user to get their regional and language settings, including the locale and country.

    I hope this helps. Mark the answer as accepted if this fits your needs.


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.