How to perform a move-mailbox based on group membership

 07 Apr 2008 03:00:12 pm

This example is based on how to easily move users based on group membership in Exchange 2007, however the same process could easily be used against a get-user, get-mailbox, import-csv, etc. (of course filtering the results we're interested in). The important thing is that we end up with an array that contains the list of users we want and then to pipe that to the move-mailbox cmdlet.

$group = get-group <groupname> | select members

Lets take a look at what I just loaded into $group:

{user1, user2, user3}

Now what I'm really interested in is an array under $group.members:

: …
: …
: …
: …
: …
: …
: user1

Based on this query the users are stored in an array under $group.members with the Name under the $_.Name field. I could just move them all by doing a:
$group.members | foreach { move-mailbox $_.Name -TargetDatabase <mbx server><mbx DB> -ValidateOnly }

(Validate only so if this gets cut and pasted into a script/shell it doesn’t actually make the move)

The one problem with this is that the foreach will loop them the user list serially (moving only one user at a time before executing the next move-mailbox). However since move-mailbox is capable of executing multiple threads a more ideal solution to this is to perform a get-mailbox based on the users stored in the array and then pipe it to the move-mailbox command

$group.members | get-mailbox | move-mailbox -TargetDatabase <mbx server><mbx DB> -ValidateOnly

Category : Exchange | Posted By : Erik | Comments [0] | Trackbacks [0]


The URI to TrackBack this entry is :


Add Your Comment




Email Address (Optional)

Home Page (Optional)

Security Code
Click to display security code
Note:Security Code valid for only 10 minutes!
Need to enable javascript & accept cookies to work
Please enter the security code as displayed :

NOTE: All comments are now moderated and will not immediatly appear.