Skip to Main Content
Active Directory, 3rd Edition
book

Active Directory, 3rd Edition

by Joe Richards, Robbie Allen, Alistair G. Lowe-Norris
January 2006
Beginner content levelBeginner
832 pages
27h 52m
English
O'Reilly Media, Inc.
Content preview from Active Directory, 3rd Edition

Moving a Mailbox

There are times when you want to move mailboxes from one Exchange server to another. The reason for the move may be for a migration from an older Exchange server to a new one (e.g., Exchange 5.5 to Exchange 2003), to better load balance mailboxes between Exchange Servers, or any number of other reasons. This is a very simple task to handle through a CDOEXM script. The following code shows how to move a mailbox:

    ' This code moves a mailbox.
    Option Explicit
    Dim strUserDN, strServer, strSGName, strMailStoreName, strSearch
    Dim objSrv, strSg, strSGUrl, strMBUrl, objUser
    ' ------ SCRIPT CONFIGURATION ------
    strUserDN  = "<UserDN>" ' e.g. cn=DrAmy,cn=Users,dc=mycorp,dc=com
    strServer  = "<Exchange Server>"         ' e.g. ExchServer2
    strSGName  = "<Storage Group Name>"      ' e.g. SG1
    strMailStoreName = "<MailBox Store Name>" ' e.g. DB1
    ' ------ END CONFIGURATION ---------
    ' Find Storage Group URL and Generate Mailbox Store URL
    strSearch = "cn=" & strSGName  & ","
    Set objSrv = CreateObject("CDOEXM.ExchangeServer")
    objSrv.DataSource.Open strServer
    For Each strSg In objSrv.StorageGroups
       If (instr(1,strSg,strSearch,1)>0) Then
          strSGUrl = strSg
          Exit For
       End If
    Next
    strMBUrl = "LDAP://cn=" & strMailStoreName & "," & strSGUrl

    ' Attach to user and move mailbox
    Set objUser = GetObject("LDAP://" & strUserDN)
    objUser.MoveMailbox(strMBUrl)
    WScript.Echo "Successfully moved mailbox."

Tip

Moving a mailbox requires Exchange Service Administrator permissions, plus additional permissions on user objects. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Active Directory, 4th Edition

Active Directory, 4th Edition

Brian Desmond, Joe Richards, Robbie Allen, Alistair G. Lowe-Norris
Active Directory, Second Edition

Active Directory, Second Edition

Robbie Allen, Alistair G. Lowe-Norris

Publisher Resources

ISBN: 0596101732Supplemental ContentErrata Page