Its safe to say that one of the most useful features of Office 365 from an administrative point of view is Directory-Sync via Forefront Identity Manager (FIM).
When given the task to add a new email alias/address to all users, we can simply add to the existing Proxy Address attribute in Active directory programmatically through PowerShell (and sync it up to the cloud using FIM). The code snippit below will take the take each users first& last names plus the $proxydomain to add “smtp:[email protected]” to their AD user object if they reside in $usersOU.
If the “Coexistence-Configuration” PSSnapin exists on the running system a manual directory sync will be initiated.
#Args [string]$proxydomain = "@resdevops.com"; #Proxy domain [string]$usersOU = "OU=Staff_Accounts,DC=resdevops,DC=com"; #OU to apply changes [string]$powersnapin = "Coexistence-Configuration"; #Directory Sync PS-Snapin name [int]$count = 0 ; Import-Module ActiveDirectory Get-ADUser -Filter "*" -SearchScope Subtree -SearchBase "$usersOU" -Properties ProxyAddresses, givenName, Surname | foreach-object { Write-Host "Editing user: $_.SamAccountName" if ($_.Proxyaddresses -match $_.givenName+"."+$_.Surname+$proxydomain) { Write-Host "Result: Proxy Address already exists; No action taken." } else { Set-ADUser -Identity $_.SamAccountName -Add @{Proxyaddresses="smtp:"+$_.givenName+"."+$_.Surname+$proxydomain} Write-Host "Result: Added proxy address to Account" $count++ } } #Execute Office 365 Directory Sync if possible $CheckSnapin = Get-PSSnapin -Registered $powersnapin -EA SilentlyContinue if ($CheckSnapin) { Add-PSSnapin Coexistence-Configuration; Start-OnlineCoexistenceSync Write-Host "`n `n ******Added proxy address with DirSync******" } else { Write-Host "`n `n ******Added Proxy address; Please initiate a Directory Sync Manually******" } Write-Host "Sucessfully Edited" $count "users"-Patrick