#Create NewUser Mailbox By Alberto Igbinedion
#Date created : 20/08/2015

$SamAccountName = Read-Host "Enter Username"
$Email =  Read-Host "Enter EmailAddress"
$Alias = $Email.Split("@")[0]

Get-User $SamAccountName |

% {

     Enable-Mailbox -Identity $samaccountname -Alias  $Alias -PrimarySmtpAddress $Email -database "Mailbox Database 1539870071"

     Set-Mailbox -Identity $SamAccountName -EmailAddressPolicyEnabled $True

}

     Write-Host "$SamAccountName's MailBox Created" -ForegroundColor Green

<#

# Read Me Help Tips
<#
Remove Mailbox and leave the user AD Object:

    Disable-mailbox "Username" 

To take the 1st part (0) of string before the @ symbol of an email Testuser@ons.gov.uk Email
    $Alias=$Email.Split("@")[0]
To Replace any space with a .
    $Alias=$DisplayName.Replace('\s','.')[0]
    
    #>