Exchange Server 2007: Bulk mailbox-enabling users using Exchange Shell
Posted by Bharat Suneja at 8:49 AM
First we need to find the users without mailboxes. The get-user command will list all users. The RecipientType property of the user is either User or UserMailbox. As the name clearly suggests, those with UserMailbox as RecipientType are already mailbox-enabled – leaving those with RecipientType User.
You can enable all users with RecipientType User:
get-user | where-object{$_.RecipientType –eq “User”}
Yes, that may not be a great idea! So let’s filter these users. If these users reside in a particular Organizational Unit, we can restrict our search to that OU. In this case, we’ll look for users in the OU called “People”:get-user –organizationalUnit people | where-object{$_.RecipientType –eq “User”}
Now we get a list of all users (who are not mailbox-enabled) from that OU. We can further restrict this list to all users who are members of a particular department. Since Sales is our favorite department, let’s pick Sales:get-user –organizationalUnit people | where-object{$_.RecipientType –eq “User” -and $_.department –eq “Sales”}
Now we’ve got a smaller list of folks – those residing in the People OU belonging to Sales dept. and aren’t mailbox-enabled yet. Let’s go ahead and mailbox-enable these users:get-user –organizationalUnit people | where-object {$_.RecipientType –eq “User” -and $_.department –eq “Sales”} | Enable-Mailbox –Database “EXCHANGE1\Mailbox Database” | get-mailbox | select name,windowsemailaddress,database
The above command mailbox-enables these users and outputs a list of their names, default email address, and the mailbox Store on which their mailbox(es) reside.Similarly, you can also use other user attributes of user accounts like city, state, country, etc. to selectively mailbox-enable users.
The WOW! factor and what really makes it a fun process is the fact that once you get a hang of the syntax and know what you're looking for, the entire process happens really quickly.
PowerShell / Exchange shell does to VBS scripts what scripting did to repetitive GUI tasks.
Labels: Administration, Exchange Server 2007, Exchange Shell

Exchangepedia Blog is read by visitors from all 50 US States and 150 countries world-wide


13 Comments:
This is simply fantastic !
Are the variables and syntax the same for adding resources? I've got an OU full of conference rooms I'd like to auto-provision email accts for to use in Outlook calendaring. If the AD accts are disabled (which they are), will Power/ExchangeShell know to create a room mailbox instead of a user mailbox?
It would seem I found my own answer (gotta love that feeling!). Here's the command if you want to take an entire OU in AD and turn it into room mailboxes in Exchange 2007: (I ran it from the mailbox server but it shouldn't matter)
get-user -organizationalUnit "OUNameHere" | where-object{$_.RecipientType -eq "User"} | Enable-Mailbox -Database "MBXservernameHERE\mailbox database" -Room
Actually quite simple when I compare the new cmdlet to the old ;)
This doesn't set many switches or parameters on the mailbox but when you look at it in the Exchange Mgmt Console you'll see it listed as a "Room Mailbox". Man, PowerShell KIX (no pun intended)! Also remember - for this to work, the user acct in AD must be disabled (essentially any user accts you want to use for resource mailboxes need to be disabled prior to trying to create a mailbox for the acct). If it isn't, you'll get a nice red error meesage in PowerShell saying "Doh!". On the upside, the errors in PowerShell are much more informative than any I've seen to date where scripting is concerned!
Also, if you have other accts in the OU you're "harvesting" that already have mailboxes created for them, don't worry, it won't create additional mailboxes for rooms. The above cmdlet specifically looks for "user" object types; if you've already got a mailbox assigned to a user acct, the object type becomes "UserMailbox" and is skipped by the cmdlet. One of the nice things about the script is that when it finishes it lists all the users that had mailboxes created for them.
Hopefully this helps someone else out there...
I've been a real cynic of Powershell, but this cmdlet has converted me !!
Hi ,
I have installed excahnge 2007 on a new server ,current email server is exch . 2000 pls some one tell me how to migrate the mail boxex from 2000 to 2007 ,my new server exch organization is identical to existing server.
Ibrahim
Thanks for your insight! But one thing I'm stumped on... how can I add an alias as the users first.lastname@mydomain.com? Not just flastname@mydomain.com?
Is there a way?
THANK YOU!
Ibrahim,
If you installed the new server in the same Exchange Organization, you should be able to move mailboxes from the 2000 server to the 2007.
Bharat
Hi Tom,
If you mean email addresses - the default set of email addresses are controlled by the Email Address Policy (EAP). You will need to modify it to add a similar alias address (known as proxyAddress) to all recipients covered by that EAP.
If you want to do this for a single user/mailbox/recipient, you can go to the mailbox/recipient's properties in the Exchange console and add it from the E-Mail Addresses tab.
If you want to change the default email address (this is what is used to send and reply to messages, regardless of any number of proxyAddresses a recipient may have), you will need to uncheck "Automatically update e-mail addresses based on email address policy".
To do this using the Exchange shell, refer to previous post: "HOW TO: Add additional email addresses to a recipient".
To do this for Public Folders, refer to previous post: "HOW TO: Add Email Addresses To Public Folders"
It`s really fantastic. I`m search a week over Internet, try csv and and from console. But it`s method much more simplest and faster. Thank very much to autor.
How can I sort/filter users by group before enabling mailbox?
A bit late, but for others that follow... to answer gitenberg you need to use the -filter option, e.g.
get-user -filter {memberofgroup -eq "cn=group,ou=orgunit,dc=network,dc=lan"}
hope that helps others.
Your instructions work great. But how do you spread the mailboxes created over several storage groups
damianini,
That would require a script to get all mailbox databases in the Org or one server or have the database names fed manually.
Alternatively, you can filter users based on OU/department or some other common attribute and place those on one mailbox database.
Post a Comment
Links to this post:
Create a Link
<< Home