Below 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
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
Thanks for the comment, modified now.