To get the locale and country for multiple Microsoft 365 users using the Microsoft Graph API, you can follow these steps:
- Set Up Your Environment:
- Install the Microsoft Graph PowerShell SDK if you haven’t already:
Install-Module Microsoft.Graph.beta -Scope CurrentUser
- Install the Microsoft Graph PowerShell SDK if you haven’t already:
- Authenticate:
- Authenticate to Microsoft Graph:
Connect-MgGraph -Scopes "User.Read.All"
- Authenticate to Microsoft Graph:
- 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" }
- Use the following PowerShell script to get the locale and country for multiple users:
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.