In today's global workplace, organizations frequently communicate across multiple languages. Microsoft Outlook provides a built-in message translation feature that automatically translates incoming emails into a user's preferred language.
As an IT administrator, you may need to enable message translation for all users in your Microsoft 365 domain. This article walks through a Graph PowerShell script that enables message translation and sets the default translation language to French for all users.
The following Graph PowerShell script enables message translation for all users in a domain and sets their default translation language to French ("fr").
# Install the Microsoft Graph PowerShell module if not already installed
# Install-Module -Name Microsoft.Graph -Scope CurrentUser
# Connect to Microsoft Graph with the necessary permissions
Connect-MgGraph -Scopes "MailboxSettings.ReadWrite.All"
# Retrieve all users in the domain
$Users = Get-MgUser -Filter "UserType eq 'Member'" -Select Id, UserPrincipalName
# Check if users are found
if ($Users.Count -eq 0) {
Write-Output "No users found in the domain."
Disconnect-MgGraph
return
}
# Set the translation language to French for all users
foreach ($User in $Users) {
$UserId = $User.Id
$UserUPN = $User.UserPrincipalName
$Settings = @{
messageTranslationSettings = @{
enabled = $true
targetLanguage = "fr" # Set to French
}
}
try {
Update-MgUserMailboxSetting -UserId $UserId -BodyParameter $Settings
Write-Output "Enabled message translation to French for $UserUPN"
} catch {
Write-Output "Failed to update translation setting for $UserUPN: $_"
}
}
# Disconnect from Microsoft Graph
Disconnect-MgGraph
This script automates enabling message translation for all users by following these steps:
Organizations often have employees in multiple countries. Modify the script to assign different languages based on user departments:
$LanguageMapping = @{
"Sales" = "fr" # French for Sales team
"Support" = "es" # Spanish for Support team
"Marketing"= "de" # German for Marketing team
}
foreach ($User in $Users) {
$UserDepartment = Get-MgUser -UserId $User.Id | Select-Object -ExpandProperty Department
$TargetLanguage = $LanguageMapping[$UserDepartment] ?? "en" # Default to English if not
mapped
$Settings = @{
messageTranslationSettings = @{
enabled = $true
targetLanguage = $TargetLanguage
}
}
Update-MgUserMailboxSetting -UserId $User.Id -BodyParameter $Settings
Write-Output "Set translation language to $TargetLanguage for $($User.UserPrincipalName)"
}
If you want to apply the translation setting only to specific Microsoft 365 groups, modify the script to target users within a particular group:
$GroupId = "12345678-90ab-cdef-1234-567890abcdef"
$Users = Get-MgGroupMember -GroupId $GroupId -All
Keep track of users who have been updated by logging their details to a CSV file:
$Users | Select-Object UserPrincipalName, Id | Export-Csv -Path "UpdatedUsers.csv" -
NoTypeInformation
To ensure message translation settings are consistently applied, schedule the script to run daily or weekly using Windows Task Scheduler or Azure Automation.
Error 1: Access Denied (403 Forbidden)
Error 2: No Users Found
Error 3: Invalid Language Code
Error 4: API Throttling
Start-Sleep -Seconds 1
Enabling message translation in Outlook using Graph PowerShell improves cross-language communication and enhances global collaboration. This script automates the process by setting French ("fr") as the default translation language for all users.
By modifying the script, administrators can: