• 1. London, UK
  • 2. New York, NY
  • 3. Sydney, Australia
  • 4. Melbourne, Australia
  • 5. Chicago, IL
  • 6. Bellevue, WA
  • 7. Paris, France
  • 8. Houston, TX
  • 9. Stockholm, Sweden
  • 10. San Francisco, CA

Thursday, December 14, 2006

 

Exchange Server 2007: Bulk mailbox-enabling users using Exchange Shell

Posted by Bharat Suneja at 8:49 AM
I’d written about how to bulk create mailboxes (including user accounts) from a CSV file [read previous post: Exchange Server 2007: Bulk creation of mailboxes using Exchange Management Shell]. This is in response to the reader who posted a comment asking for a way to mailbox-enable existing user accounts.

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: , ,

13 Comments:

January 30, 2007 7:35 AM
Anonymous tizedboy said...

This is simply fantastic !

 
February 23, 2007 11:01 AM
Anonymous Anonymous said...

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?

 
February 26, 2007 6:28 AM
Anonymous Anonymous said...

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...

 
June 1, 2007 7:50 AM
Anonymous Boso said...

I've been a real cynic of Powershell, but this cmdlet has converted me !!

 
June 9, 2007 12:17 AM
Blogger Ibrahim said...

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

 
July 26, 2007 4:16 PM
Blogger Tom said...

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!

 
July 26, 2007 4:35 PM
Blogger Bharat Suneja said...

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

 
July 26, 2007 4:44 PM
Blogger Bharat Suneja said...

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"

 
August 6, 2007 12:46 AM
Anonymous Andrew said...

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.

 
August 19, 2007 9:01 AM
Anonymous gitenberg said...

How can I sort/filter users by group before enabling mailbox?

 
March 24, 2008 11:22 PM
Anonymous Anonymous said...

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.

 
April 7, 2008 1:43 PM
Blogger damianini said...

Your instructions work great. But how do you spread the mailboxes created over several storage groups

 
May 11, 2008 11:59 AM
Blogger Bharat Suneja said...

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