Turning On Message Translation in Outlook Using Graph PowerShell

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.

  1. The Script
  2. 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
  3. How the Script Works
  4. This script automates enabling message translation for all users by following these steps:

    1. Connects to Microsoft Graph:
      • Uses Connect-MgGraph with the MailboxSettings.ReadWrite.All permission to modify mailbox settings.
    2. Retrieves All Users in the Organization:
      • Filters only active members (UserType eq 'Member') to exclude guest and shared accounts.
    3. Applies Translation Settings:
      • Uses Update-MgUserMailboxSetting to enable message translation and set French ("fr") as the target language.
    4. Handles Errors Gracefully:
      • If an update fails for a user, it logs the error instead of stopping the script.
    5. Disconnects from Microsoft Graph:
      • Ends the session to free up resources.
  5. Further Enhancements
    1. Set Different Languages for Different Departments
    2. 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)"
      }
    3. Apply the Setting Only to Specific Groups
    4. 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
    5. Export Updated Users to a CSV File
    6. 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
    7. Automate the Script Using Task Scheduler
    8. To ensure message translation settings are consistently applied, schedule the script to run daily or weekly using Windows Task Scheduler or Azure Automation.

  6. Possible Errors & Solutions
  7. Error 1: Access Denied (403 Forbidden)

    • Cause: Missing required permissions.
    • Solution: Ensure MailboxSettings.ReadWrite.All permission is granted in Azure AD and that admin consent is provided.

    Error 2: No Users Found

    • Cause: The script is unable to fetch user accounts.
    • Solution Run this command to confirm user retrieval:Get-MgUser -All | Select-Object DisplayName, UserPrincipalName

    Error 3: Invalid Language Code

    • Cause: The language code provided is incorrect.
    • Solution: Ensure that the target language follows ISO 639-1 codes. Example:
      • English: en
      • French: fr
      • Spanish: es
      • German: de

    Error 4: API Throttling

    • Cause: Too many requests sent in a short period.
    • Solution: Introduce a short delay between requests:

    Start-Sleep -Seconds 1

  8. Conclusion

  9. 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:

    • Assign different languages based on departments
    • Apply settings only to selected groups.
    • Automate translations at scale for thousands of users.