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:

$group
Members
------
{user1, user2, user3}

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

$group.members
<excerpt>
Rdn
: …
Parent
: …
Depth
: …
DN
: …
DomainId
: …
ObjectGuid
: …
Name
: user1
</excerpt>

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

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



1
Mar 2008 April 2008 May 2008
S M T W T F S
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30    

Categories

Recent

Archives

User List

Search

Syndication

rss0.90
rss_2.0