Changing the preferred language in office365 in BULK

If you have office365 with active directory sync here is a simple way of changing the AD users preferred language in bulk!

$UpnPath = "C:\OfficeLanguageScript\UsersToCheck.txt"
$DoneUpnPath = "C:\OfficeLanguageScript\DoneUsers.txt"
$UpnPath = "C:\OfficeLanguageScript\UsersToCheck.txt"
$C = Get-ADUser -Filter * -SearchBase 'OU=SWE,DC=domain,DC=com' | Select-Object -Property SamAccountName | Out-String
Write-Host $C
#Creates file with all users UPN
if (!(Test-Path $UpnPath))
   New-Item -Path "C:\OfficeLanguageScript\" -Name "UsersToCheck.txt" -ItemType "file" -Value $C
   Write-Host "Created new file and text content added"
  Remove-Item –path $UpnPath
  New-Item -Path "C:\OfficeLanguageScript\" -Name "UsersToCheck.txt" -ItemType "file" -Value $C
  Write-Host "File already exists so it was cleared and filled with new data"
(Get-Content $UpnPath | Select-Object -Skip 3) | Set-Content "C:\OfficeLanguageScript\UsersToCheck.txt"
Write-Host "Removing first three rows"
(Get-Content $UpnPath | Foreach {$_.TrimEnd()}) | Set-Content "C:\OfficeLanguageScript\UsersToCheck.txt"
Write-Host "removing trailing space of file"
(Get-Content $UpnPath | ? {$_.trim() -ne "" }) | Set-Content "C:\OfficeLanguageScript\UsersToCheck.txt"
Write-Host "removing trailing empty lines"
#Check if there is a file with done users
if (!(Test-Path $DoneUpnPath))
   New-Item -Path "C:\OfficeLanguageScript\" -Name "DoneUsers.txt" -ItemType "file"
   Write-Host "Created new DoneUsers file and text content added"
#Compare files
$strReference = Get-Content $UpnPath
$strDifference = Get-Content $DoneUpnPath
#If null array.... ffs....
if ($strReference -eq $null) { $strReference = "" }
if ($strDifference -eq $null) { $strDifference = "" }
#Removes empty inputs
$strReference = $strReference.Where({ $_ -ne "" })
$strDifference = $strDifference.Where({ $_ -ne "" })
#Compares the lists
$users = Compare-Object $strReference $strDifference
Write-Host "Users to change language on"
Write-Host $users.InputObject
foreach ($user in $users.InputObject)
  Set-ADUser $user –replace @{PreferredLanguage="sv-SE"}
  Add-Content $DoneUpnPath $user

Lämna ett svar

Din e-postadress kommer inte publiceras. Obligatoriska fält är märkta *