Switch Systems Blog

Powershell snippet – creating new user mailboxes

by on Aug.20, 2010, under Technical

Want to know the powershell commands for creating and mailbox-enabling a user?

This function assumes you have a user account called ‘stdUser’ which you base your users on – you can always replace this or omit this as necessary.

/* Replace domainname.local, sbs2008.domainname.local as appropriate. */
Function CreateUser { 
   Param ($userinfo) 
   $newUser = New-Mailbox –UserPrincipalName ($userinfo.samAccountName + "@domainname.local") -alias $userinfo.samAccountName –database "First Storage Group\Mailbox Database" –name ($userinfo.givenName + ' ' + $userinfo.sn) –OrganizationalUnit $userinfo.OU -DomainController 'sbs2008.domaniname.local' –password (convertto-securestring -string $userinfo.Password -AsPlainText -Force ) –FirstName $userinfo.givenName –LastName $userinfo.sn –DisplayName ($userinfo.givenName + ' ' + $userinfo.sn) –ResetPasswordOnNextLogon $true -TemplateInstance $mailboxTemplate
}

// usage from a CSV import
$mailboxTemplate = Get-Mailbox "stdUser"
$users = import-csv ".\staff_userlist.csv" 
foreach ($user in $users) { 
   CreateUser($user); 
}

As always, the powershell blog has more resources.

:,

Leave a Reply

You must be logged in to post a comment.

Looking for something?

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!