Guest User

Untitled

a guest
Jul 16th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. if(-not(Get-PSSession)) {
  2.  
  3. . 'D:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1'
  4. Connect-ExchangeServer -auto -ClientApplication:ManagementShell
  5.  
  6. }
  7.  
  8. $Mailboxes = Get-Content .\shared.txt | Get-Mailbox
  9. $ExOSuffix = "<tenant>.mail.onmicrosoft.com"
  10.  
  11. foreach($m in $Mailboxes) {
  12.  
  13. $NewAddress, $PrimaryAddress, $PrimaryAddressName = $null
  14. $PrimaryAddress = $m.EmailAddresses | Where-Object {$_.IsPrimaryAddress -and $_.PrefixString -eq "SMTP"}
  15. $PrimaryAddressName = $PrimaryAddress.AddressString -replace("@.*","")
  16. $NewAddress = $PrimaryAddressName,$ExOSuffix -join("@")
  17. $m.EmailAddresses.Add("smtp:$NewAddress")
  18. Set-Mailbox -Identity $m.Identity -EmailAddresses $m.EmailAddresses
  19.  
  20. }
Add Comment
Please, Sign In to add comment