Add an Alias to all Mailboxes of FirstL
The Goal
Add an alias for all users in office 365 of first name + first letter of last name
The Solution
First we need to connect to Office 365 using power shell
Import-Module MSOnline
$cred = Get-Credential
Connect-MsolService –Credential $cred
Second iterate over the Mailboxes and add the aliases
Get-Mailbox -resultsize unlimited |ForEach-Object {
$u = $_ | Get-User
if ($u.Lastname.length -gt 1 -and $u.FirstName.length -gt 0) {
$new = (($u.FirstName) + ($u.LastName.Substring(0,1))).tolower() + "@example.com"
Set-Mailbox $_.id -EmailAddress @{add=$new}
}
}