Creating a new mailbox with Powershell function on Exchange Server 2010

I wrote a function for Hosted Exchange 2010 to create a new mailbox on Exchange Server 2010.

1
2
3
4
5
6
7
function Add-MailUser
{
Param ($UserID, $FirstName, $LastName, $CustomerOU)
    $ADDomain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
    $ADDomainName = $ADDomain.Name
    Enable-Mailbox -Identity "$ADDomainName/$CustomerOU/$FirstName $LastName" -Alias "$UserID"
}

Usage of function:

Add-MailUser –UserID “2452” –FirstName “Yusuf” –LastName “Ozturk” -CustomerOU “Users”

I used System.Directory.Services to get Active Directory domain. Lets see how does it work:

dservices

CustomerOU is the base of your user container. Just type your OU name like “Exchange” or “Users”.