BULK CUSTOMIZE ADD SECONDARY ALIAS – OFFICE365

office-365-business-plansBelow script, Creates a secondary alias as Firstname.Lastname@domain.com & add it as Secondary address to the mailboxes in bulk.

################################################################ 
# Scripting for Office365 
################################################################ 
 
#Script Written by : Kingson Jebaraj 
#Version : 1.0 
 
# ============================================================================================== 
# Crendentials and Logon 
# ============================================================================================== 
 
Get-PSSession | Remove-PSSession 
Get-Module tmp* | Remove-Module 
$administrator = "Administrator@domain.com" 
$password = Get-Content "C:\Scripts\pass.txt" | ConvertTo-SecureString -AsPlainText -force 
$credential = New-Object System.Management.Automation.PSCredential $administrator,$password 
$Server"https://outlook.office365.com/powershell-liveid/" 
$session = New-PSSession -Authentication basic -Credential $credential -ConnectionUri $Server -Configuration Microsoft.Exchange -AllowRedirection 
Import-PSSession $session 
 
# ============================================================================================== 
# Getting Users with Firstname & Lastname to apply 
# ============================================================================================== 
 
 
$mbxs=Get-MailBox 
foreach($m in $mbxs) { 
    $newalias=""  
    $u=Get-User $m.alias; 
    if($u.FirstName.trim() -ne "") { 
        $newalias=$u.FirstName.trim() 
        if($u.LastName.trim() -ne "") { 
            $newalias +"."+$u.LastName.trim() 
        } 
    }    
    if($newalias.trim() -ne "") { 
        $newsmtpalias="smtp:"+$newalias+"@domain.com" 
        if(-not ($m.EmailAddresses -contains $newsmtpalias)) { 
            $m.EmailAddresses.add($newsmtpalias) 
            Set-mailbox -Identity $m.Identity -EmailAddresses $m.EmailAddresses 
        } 
    } 
      
 } 
 
 Write-Host Successfully Applied SMTP Settings 
 
# ============================================================================================== 
# Closing Session 
# ============================================================================================== 
 
Get-PSSession | Remove-PSSession
 Category: Office365
About Kingson Jebaraj

Microsoft MVP, Blogger, Owner and Publisher for Cloudexchangers.com, Microsoft TechNet Author, Solution Architect, Former Office365 Technical Lead for Microsoft(Partner) Extensive knowledge and experience in Microsoft Exchange and Cloud Messaging Services and has got more exposure on Messaging environment deployment,migration,designing and other project management activities, I have earned real time experience in handling multi-site distributed critical large environment of messaging system. Been awarded as an MVP (Microsoft Most Valuable Professional) for Office Servers and services from Microsoft for an exceptional real world contribution made through Microsoft forums and other Microsoft communities. Currently working as “Solution Architect” on Private/Public cloud and SaaS environment for Pacific Controls, UAE, Dubai. One of the largest TIER III certified green data center campus in the middle east.

Related articles

2 Comments

  1. Reply

    Good script, if copying and pasting watch for the – before ConnectionUri on the “$session = New-PSSession” line.

    It should be
    $session = New-PSSession -Authentication basic -Credential $credential –ConnectionUri $Server -Configuration Microsoft.Exchange -AllowRedirection

Leave a Reply