Skip to content

Exchange Online helper scripts

Add missing '.mail.onmicrosoft.com' Proxy Address

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
cls
#Variables
$Domain = '<tenant>.mail.onmicrosoft.com'

#Get all users in ActiveDirectory
$Users = Get-ADUser -Filter 'msExchMailboxGuid -like "*"' -Properties ProxyAddresses

#Some output is always nice
Write-Host -Object "Processing $Users.Count users..." -ForegroundColor Green

#Go through all users
foreach ($User in $Users)
{
  if (($user.Name -notlike "*mailbox*") -and ($user.Name -notlike "*federated*"))
  {
      #Check if <domain>.mail.onmicrosoft.com alias is present, if not add it
      if ($User.Proxyaddresses -like "*$Domain*")
      {
        #Write-Host -Object "$User.SamAccountName has an alias matching $Domain..." -ForegroundColor Yellow
      }
      else
      {
        $Alias = $User.SamAccountName + '@' + $Domain
        Set-ADUser $User -Add @{
          Proxyaddresses = "$Alias"
        }
        Write-Host -Object "Alias added to $User.SamAccountName..." -ForegroundColor Green
      }
  }
}
Write-Host -Object 'Done' -ForegroundColor Green

Start mailbox migration for a list of UPNs

1
2
3
4
5
6
7
$ArchiveUPNs = Get-Content -Path C:\_Sources\ArchiveUPN.txt
$RemoteHostName = 'mail.domain.pt'
$TargetDeliveryDomain = 'tenant.mail.onmicrosoft.com'
$LargeItemLimit = 2000
$BadItemLimit = 2000

$ArchiveUPNs | New-MoveRequest -Identity $_ -RemoteCredential $Credentials -Remote -RemoteHostName $RemoteHostName -BatchName $_ -PrimaryOnly -TargetDeliveryDomain $TargetDeliveryDomain -LargeItemLimit $LargeItemLimit -AcceptLargeDataLoss -BadItemLimit $BadItemLimit -SuspendWhenReadyToComplete