Announcement

Collapse
No announcement yet.

Export Exchange User Mailbox Tool

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Export Exchange User Mailbox Tool

    Hey Everyone,

    Here is an tool I wrote for exporting a users Exchange Mailbox to a PST file. We use this as we are archiving an account (as well as a script to export certain parts of the roaming profile).

    I'm sure someone has a cleaner method but the script is useful for us anyway

    I've tried to document it as much as possible but please feel free to ask me any questions.

    At the very least, you need to modify the following variables before using the script.
    1. <span style="font-weight: bold">exportFolder</span> - This must be on a drive that has enough space for the exported mailbox file. Due to a security limit in .NET applications (ADModify) this has to either be a local folder or you need to change the script to run ADModify from another location.
    2. <span style="font-weight: bold">mailBoxPath</span> - This is the full mailbox path of your exchange server. The format of ours is (do not put quotes around this):
    /O=LONG DOMAIN NAME/OU=FIRST ADMINISTRATIVE GROUP/CN=RECIPIENTS/CN=
    3. <span style="font-weight: bold">exchangeServerName</span> - The exchange server to dump the email from.
    4. <span style="font-weight: bold">sharedToolsPath</span> - We keep all of our shared tools and configs on a network share for easy use and a central place to update. This is a variable to point to the tools path.
    5. <span style="font-weight: bold">adModifyToolPath</span> - We keep a copy of ADModify in a sub folder of our sharedToolsPath called ADModify. Change to reflect where the folder is.
    6. <span style="font-weight: bold">adBaseDN</span> - Change this to reflect your domain info. Needs quotes around it.
    7. <span style="font-weight: bold">adDomainName</span> - Change to reflect your domain name.

    A quick summary of what steps this script performs:
    1. Checks a bunch of stuff and tried to create a export folder and grab any tools it needs.
    2. Builds the config files it needs for ExMerge to export the mailbox.
    3. Gives the user who is running this script "FULL CONTROL" to the given Mailbox using ADModify.
    4. Exports the email to a PST file using ExMerge.
    5. Opens the ExMerge log file in NOTEPAD for a manual check for errors.
    6. Removes the current users rights (given in step 3) to the mailbox (this might be something you don't want depending on your corp security policy).
    7. Cleans up some files and the local copy of ADModify.

    Ok, here is the batch file (warning it's long):
    <div class="ubbcode-block"><div class="ubbcode-header">Quote:</div><div class="ubbcode-body"><div class="ubbcode-block"><div class="ubbcode-header">Code:</div><div class="ubbcode-body ubbcode-pre" ><pre>
    @echo off
    :: Purpose: Batch File to export a users exchange mailbox to pst file
    :: Author: Evan Waite
    :: Date Created: Nov 03, 2005
    :: Date Modified: Nov 04, 2005
    :: Comments: Inline Comments for each step. Instructions below
    :: Changelog: Nov 03, 2005 - Initial Version
    :: Nov 04, 2005 - Integrate with ADModify to handle granting and removing Mailbox rights
    ::
    :: Requirements:
    :: You need the following installed on your workstation prior to using the script
    :: - Exchange 2003 Admin tools (2000 might work but not tested)
    :: - ExMerge.exe from the Exchange 2003 Resource Kit (must be in local Exchange bin folder)
    :: - .NET Framework 1.1 Installed
    :: - ADModify (http://www.gotdotnet.com/workspaces/...8-3e44523f32e2)
    ::
    :: License:
    :: Feel free to use this script in any way but please credit me for my work. Oh and if you make any money, pleaes send BEER!
    ::
    :: Instructions:
    :: 1. Modify any parameters (variable names are pretty clear)
    :: 2. Manually Run this file with the following syntax or call it from the Hyena tools menu.
    :: export-exchange-mailbox.bat username
    :: 3. The log file will open after. Check for any errors

    :: Sets some date variables assuming the MM/DD/YYYY format. These are used in the export log file
    set thisMonth=%date:~4,2%
    set thisDay=%date:~7,2%
    set thisYear=%date:~12,2%

    :: Variables
    set exportFolder=C:\Exported-Mailboxes
    set mailBoxPath=/O=DOMAIN NAME/OU=FIRST ADMINISTRATIVE GROUP/CN=RECIPIENTS/CN=
    set exchangeServerName=ExchangeServerName
    set exportUserName=%1
    set exchangeBinFolder=C:\Program Files\Exchsrvr\bin
    set exchMemDLL=exchmem.dll
    set exMergeEXE=ExMerge.exe
    set sharedToolsPath=\\server\Hyena-Shared\Tools
    set legacyExchangeDN=%mailBoxPath%%exportUserName%
    set exportMailBoxFile=mailbox-%exportUserName%.txt
    set exportSettingFile=exmerge-%exportUserName%.ini
    set exportLogFile=exmerge-%exportUserName%-%thisMonth%-%thisDay%-%thisYear%.log
    set exportLoggingLevel=1
    set textViewerApplication=notepad.exe
    :: These are Variables for ADModify
    set adminUserName=%USERNAME%
    set adModifyToolPath=ADModify
    set adModifyToolEXE=ADModcmd.exe
    set adModifyToolOptions=-s
    set adModifyToolAddAccess=-addtomailboxrights
    set adModifyToolRemoveAccess=-removefrommailboxrights
    set adModifyToolAddAccessMask=ACE_MB_FULL_ACCESS
    set adModifyToolRemoveAccessMask=ALL
    set adBaseDN=&quot;DC=domain,DC=com&quot;
    set adLDAPFilter=&quot;(sAMAccountName=%exportUserName %)&quot;
    set adDomainName=DOMAIN
    :: Debugging
    :: If you are having problems, set debugEnabled=1
    :: this will keep the exportMailBoxFile, exportSettingFile and run export with verbose logging
    set debugEnabled=0
    :: If debugging is enabled, bump the exportLoggingLevel to verbose
    IF %debugEnabled%==1 set exportLoggingLevel=3


    :: Check to make sure everything is in order

    :: Check to see if you passed in a username parameter. If not, echo the syntax and exit
    IF &quot;%1&quot; == &quot;&quot; (
    echo Error: Missing username parameter
    echo Please use the following syntax:
    echo export-exchange-mailbox.bat username
    GOTO EOF
    )

    :: Check to see if the export folder exists. Tries to create it
    IF /I NOT EXIST %exportFolder% (
    echo Error: The %exportFolder% folder does not exist
    echo Trying to create it
    mkdir %exportFolder%
    )

    :: A second check check to see if the export folder exists. Dies if it doesn't exist.
    IF /I NOT EXIST %exportFolder% (
    echo Error: The %exportFolder% folder does not exist
    echo Please edit this file and set the exportFolder variable
    GOTO EOF
    )

    :: Check to see if the exchange bin folder exists. Dies if it doesn't exist.
    IF /I NOT EXIST &quot;%exchangeBinFolder%&quot; (
    echo Error: The %exchangeBinFolder% folder does not exist
    echo Please edit this file and set the exchangeBinFolder variable
    GOTO EOF
    )

    :: Check to see if exchmem.dll in the exchange bin folder exists. Dies if it doesn't exist.
    IF /I NOT EXIST &quot;%exchangeBinFolder%\%exchMemDLL%&quot; (
    echo Error: The %exchMemDLL% was not found in %exchangeBinFolder%
    echo You may not have the exchange admin tools installed.
    echo Please verify you have the tools installed and edit any path settings in this file.
    GOTO EOF
    )

    :: Check to see if ExMerge.exe is in the exchange bin folder. Tries to grab from an alt location
    IF /I NOT EXIST &quot;%exchangeBinFolder%\%exMergeEXE%&quot; (
    echo Error: The %exMergeEXE% was not found in %exchangeBinFolder%
    echo Trying to copy the file from an alternate location
    copy %sharedToolsPath%\%exMergeEXE% &quot;%exchangeBinFolder%\&quot;
    IF ERRORLEVEL 1 (
    echo Can not seem to find %sharedToolsPath%\%exMergeEXE%
    echo Exiting the batch file
    GOTO EOF
    )
    IF ERRORLEVEL 0 (
    echo Successfully copied %exMergeEXE% into %exchangeBinFolder%
    echo Continuing to next step
    )
    )

    :: Check to see if the local ADModify folder exists. Tries to create it
    IF /I NOT EXIST %exportFolder%\%adModifyToolPath% (
    echo Error: The %exportFolder%\%adModifyToolPath% folder does not exist
    echo Trying to create it
    mkdir %exportFolder%\%adModifyToolPath%
    )

    :: A second check check to see if the local ADModify folder exists. Dies if it doesn't exist.
    IF /I NOT EXIST %exportFolder%\%adModifyToolPath% (
    echo Error: The %exportFolder%\%adModifyToolPath% folder does not exist
    echo Please edit this file and set the adModifyToolPath variable
    GOTO EOF
    )

    :: Check to see if ADModcmd.exe is in the local ADModify folder. Tries to grab from an alt location
    IF /I NOT EXIST %exportFolder%\%adModifyToolPath%\%adModifyToolEXE % (
    echo Error: The %adModifyToolEXE% was not found in %exportFolder%\%adModifyToolPath%
    echo Trying to copy the file from an alternate location
    copy %sharedToolsPath%\%adModifyToolPath% %exportFolder%\%adModifyToolPath%
    IF ERRORLEVEL 1 (
    echo Can not seem to find %sharedToolsPath%\%adModifyToolPath%\%adModifyTool EXE%
    echo Exiting the batch file
    GOTO EOF
    )
    IF ERRORLEVEL 0 (
    echo Successfully copied %adModifyToolEXE% and required files into %exportFolder%\%adModifyToolPath%
    echo Continuing to next step
    )
    )

    :: Check to see if the exportSettingFile file exists. If true, remove it
    IF /I EXIST %exportFolder%\%exportSettingFile% (
    echo Removing old %exportFolder%\%exportSettingFile% file
    del %exportFolder%\%exportSettingFile%
    )

    :: Check to see if the exportMailBoxFile file exists. If true, remove it
    IF /I EXIST %exportFolder%\%exportMailBoxFile% (
    echo Removing old %exportFolder%\%exportMailBoxFile% file
    del %exportFolder%\%exportMailBoxFile%
    )

    :: Check to see if the renamed exportPST file exists. If true, dies to avoid overwriting it
    IF /I EXIST %exportFolder%\%exportUserName%-existing-file-renamed-on-%thisMonth%-%thisDay%-%thisYear%.PST (
    echo Error: Found an existing renamed version of the exported file
    echo Please clean up these files and rerun
    GOTO EOF
    )

    :: Check to see if the exportPST file already exists. If true, renames it
    IF /I EXIST %exportFolder%\%exportUserName%.PST (
    echo Renaming old %exportFolder%\%exportUserName%.PST file
    rename %exportFolder%\%exportUserName%.PST %exportUserName%-existing-file-renamed-on-%thisMonth%-%thisDay%-%thisYear%.PST
    )

    :: Grant the current admin full rights to the User Mailbox using ADModify
    echo Giving %adDomainName%\%adminUserName% full rights to %exportUserName% mailbox
    %exportFolder%\%adModifyToolPath%\%adModifyToolEXE % -dn %adBaseDN% -f %adLDAPFilter% %adModifyToolOptions% %adModifyToolAddAccess% %adDomainName%\%adminUserName% %adModifyToolAddAccessMask%

    :: Write the required files

    :: Exported Mailboxes Files which contains the fully qualified legacyExchangeDN name
    echo Writing Mailbox file
    echo %legacyExchangeDN%&gt;&gt; %exportFolder%\%exportMailBoxFile%

    :: Exchange Merge Utility Settings File (with only the required settings)
    echo Writing ExMerge Settings File
    echo [EXMERGE]&gt;&gt; %exportFolder%\%exportSettingFile%
    echo LoggingLevel=%exportLoggingLevel% &gt;&gt; %exportFolder%\%exportSettingFile%
    echo LogFileName=%exportFolder%\%exportLogFile%&gt;&gt; %exportFolder%\%exportSettingFile%
    echo DataDirectoryName=%exportFolder%&gt;&gt; %exportFolder%\%exportSettingFile%
    echo SourceServerName=%exchangeServerName%&gt;&gt; %exportFolder%\%exportSettingFile%
    echo FileContainingListOfMailboxes=%exportFolder%\%expo rtMailBoxFile%&gt;&gt; %exportFolder%\%exportSettingFile%

    :: Run the export using the files we just wrote
    echo Exporting Email
    &quot;%exchangeBinFolder%\%exMergeEXE%&quot; -B -F %exportFolder%\%exportSettingFile%

    :: Opens the export log file in notepad
    start %textViewerApplication% %exportFolder%\%exportLogFile%

    :: Remove the admins full rights to the User Mailbox using ADModify
    echo Removing %adDomainName%\%adminUserName% full rights to %exportUserName% mailbox
    %exportFolder%\%adModifyToolPath%\%adModifyToolEXE % -dn %adBaseDN% -f %adLDAPFilter% %adModifyToolOptions% %adModifyToolRemoveAccess% %adDomainName%\%adminUserName% %adModifyToolRemoveAccessMask%

    :: Clean up the exportMailBoxFile and exportSettingFile if debugging in not enabled
    IF NOT %debugEnabled%==1 (
    del %exportFolder%\%exportMailBoxFile%
    del %exportFolder%\%exportSettingFile%
    )

    :: Clean up the local copy of ADModify
    IF /I EXIST %exportFolder%\%adModifyToolPath% (
    echo Removing %exportFolder%\%adModifyToolPath% folder
    rmdir /S /Q %exportFolder%\%adModifyToolPath%
    )

    :EOF
    echo Done!
    </pre></div></div></div></div>

    [This message has been edited by Evan.Waite (edited 12-01-2005).]

    [This message has been edited by Evan.Waite (edited 12-01-2005).]

  • #2
    Re: Export Exchange User Mailbox Tool

    I keep receiving the error message:

    Error opening message store (MSEMS). Verify that the Microsoft Exchange Information Store service is running and that you have the correct permissions to log on.

    Any thoughts why that may be?

    Comment


    • #3
      Re: Export Exchange User Mailbox Tool

      <div class="ubbcode-block"><div class="ubbcode-header">Quote:</div><div class="ubbcode-body">Originally posted by zimmesc:
      <span style="font-weight: bold">I keep receiving the error message:

      Error opening message store (MSEMS). Verify that the Microsoft Exchange Information Store service is running and that you have the correct permissions to log on.

      Any thoughts why that may be?</span></div></div>

      I answered my own question. The mailbox denied access for all domain admins. Pretty good security measure though.

      Comment


      • #4
        Re: Export Exchange User Mailbox Tool

        Does this procedure works for multiple mail boxes?


        <div class="ubbcode-block"><div class="ubbcode-header">Quote:</div><div class="ubbcode-body">Originally posted by Evan.Waite:
        <span style="font-weight: bold">Hey Everyone,

        Here is an tool I wrote for exporting a users Exchange Mailbox to a PST file. We use this as we are archiving an account (as well as a script to export certain parts of the roaming profile).

        I'm sure someone has a cleaner method but the script is useful for us anyway

        I've tried to document it as much as possible but please feel free to ask me any questions.

        At the very least, you need to modify the following variables before using the script.
        1. exportFolder</span> - This must be on a drive that has enough space for the exported mailbox file. Due to a security limit in .NET applications (ADModify) this has to either be a local folder or you need to change the script to run ADModify from another location.
        2. <span style="font-weight: bold">mailBoxPath</span> - This is the full mailbox path of your exchange server. The format of ours is (do not put quotes around this):
        /O=LONG DOMAIN NAME/OU=FIRST ADMINISTRATIVE GROUP/CN=RECIPIENTS/CN=
        3. <span style="font-weight: bold">exchangeServerName</span> - The exchange server to dump the email from.
        4. <span style="font-weight: bold">sharedToolsPath</span> - We keep all of our shared tools and configs on a network share for easy use and a central place to update. This is a variable to point to the tools path.
        5. <span style="font-weight: bold">adModifyToolPath</span> - We keep a copy of ADModify in a sub folder of our sharedToolsPath called ADModify. Change to reflect where the folder is.
        6. <span style="font-weight: bold">adBaseDN</span> - Change this to reflect your domain info. Needs quotes around it.
        7. <span style="font-weight: bold">adDomainName</span> - Change to reflect your domain name.

        A quick summary of what steps this script performs:
        1. Checks a bunch of stuff and tried to create a export folder and grab any tools it needs.
        2. Builds the config files it needs for ExMerge to export the mailbox.
        3. Gives the user who is running this script "FULL CONTROL" to the given Mailbox using ADModify.
        4. Exports the email to a PST file using ExMerge.
        5. Opens the ExMerge log file in NOTEPAD for a manual check for errors.
        6. Removes the current users rights (given in step 3) to the mailbox (this might be something you don't want depending on your corp security policy).
        7. Cleans up some files and the local copy of ADModify.

        Ok, here is the batch file (warning it's long):
        <div class="ubbcode-block"><div class="ubbcode-header">Quote:</div><div class="ubbcode-body"><div class="ubbcode-block"><div class="ubbcode-header">Code:</div><div class="ubbcode-body ubbcode-pre" ><pre>
        @echo off
        :: Purpose: Batch File to export a users exchange mailbox to pst file
        :: Author: Evan Waite
        :: Date Created: Nov 03, 2005
        :: Date Modified: Nov 04, 2005
        :: Comments: Inline Comments for each step. Instructions below
        :: Changelog: Nov 03, 2005 - Initial Version
        :: Nov 04, 2005 - Integrate with ADModify to handle granting and removing Mailbox rights
        ::
        :: Requirements:
        :: You need the following installed on your workstation prior to using the script
        :: - Exchange 2003 Admin tools (2000 might work but not tested)
        :: - ExMerge.exe from the Exchange 2003 Resource Kit (must be in local Exchange bin folder)
        :: - .NET Framework 1.1 Installed
        :: - ADModify (http://www.gotdotnet.com/workspaces/...8-3e44523f32e2)
        ::
        :: License:
        :: Feel free to use this script in any way but please credit me for my work. Oh and if you make any money, pleaes send BEER!
        ::
        :: Instructions:
        :: 1. Modify any parameters (variable names are pretty clear)
        :: 2. Manually Run this file with the following syntax or call it from the Hyena tools menu.
        :: export-exchange-mailbox.bat username
        :: 3. The log file will open after. Check for any errors

        :: Sets some date variables assuming the MM/DD/YYYY format. These are used in the export log file
        set thisMonth=%date:~4,2%
        set thisDay=%date:~7,2%
        set thisYear=%date:~12,2%

        :: Variables
        set exportFolder=C:\Exported-Mailboxes
        set mailBoxPath=/O=DOMAIN NAME/OU=FIRST ADMINISTRATIVE GROUP/CN=RECIPIENTS/CN=
        set exchangeServerName=ExchangeServerName
        set exportUserName=%1
        set exchangeBinFolder=C:\Program Files\Exchsrvr\bin
        set exchMemDLL=exchmem.dll
        set exMergeEXE=ExMerge.exe
        set sharedToolsPath=\\server\Hyena-Shared\Tools
        set legacyExchangeDN=%mailBoxPath%%exportUserName%
        set exportMailBoxFile=mailbox-%exportUserName%.txt
        set exportSettingFile=exmerge-%exportUserName%.ini
        set exportLogFile=exmerge-%exportUserName%-%thisMonth%-%thisDay%-%thisYear%.log
        set exportLoggingLevel=1
        set textViewerApplication=notepad.exe
        :: These are Variables for ADModify
        set adminUserName=%USERNAME%
        set adModifyToolPath=ADModify
        set adModifyToolEXE=ADModcmd.exe
        set adModifyToolOptions=-s
        set adModifyToolAddAccess=-addtomailboxrights
        set adModifyToolRemoveAccess=-removefrommailboxrights
        set adModifyToolAddAccessMask=ACE_MB_FULL_ACCESS
        set adModifyToolRemoveAccessMask=ALL
        set adBaseDN=&quot;DC=domain,DC=com&quot;
        set adLDAPFilter=&quot;(sAMAccountName=%exportUserName %)&quot;
        set adDomainName=DOMAIN
        :: Debugging
        :: If you are having problems, set debugEnabled=1
        :: this will keep the exportMailBoxFile, exportSettingFile and run export with verbose logging
        set debugEnabled=0
        :: If debugging is enabled, bump the exportLoggingLevel to verbose
        IF %debugEnabled%==1 set exportLoggingLevel=3


        :: Check to make sure everything is in order

        :: Check to see if you passed in a username parameter. If not, echo the syntax and exit
        IF &quot;%1&quot; == &quot;&quot; (
        echo Error: Missing username parameter
        echo Please use the following syntax:
        echo export-exchange-mailbox.bat username
        GOTO EOF
        )

        :: Check to see if the export folder exists. Tries to create it
        IF /I NOT EXIST %exportFolder% (
        echo Error: The %exportFolder% folder does not exist
        echo Trying to create it
        mkdir %exportFolder%
        )

        :: A second check check to see if the export folder exists. Dies if it doesn't exist.
        IF /I NOT EXIST %exportFolder% (
        echo Error: The %exportFolder% folder does not exist
        echo Please edit this file and set the exportFolder variable
        GOTO EOF
        )

        :: Check to see if the exchange bin folder exists. Dies if it doesn't exist.
        IF /I NOT EXIST &quot;%exchangeBinFolder%&quot; (
        echo Error: The %exchangeBinFolder% folder does not exist
        echo Please edit this file and set the exchangeBinFolder variable
        GOTO EOF
        )

        :: Check to see if exchmem.dll in the exchange bin folder exists. Dies if it doesn't exist.
        IF /I NOT EXIST &quot;%exchangeBinFolder%\%exchMemDLL%&quot; (
        echo Error: The %exchMemDLL% was not found in %exchangeBinFolder%
        echo You may not have the exchange admin tools installed.
        echo Please verify you have the tools installed and edit any path settings in this file.
        GOTO EOF
        )

        :: Check to see if ExMerge.exe is in the exchange bin folder. Tries to grab from an alt location
        IF /I NOT EXIST &quot;%exchangeBinFolder%\%exMergeEXE%&quot; (
        echo Error: The %exMergeEXE% was not found in %exchangeBinFolder%
        echo Trying to copy the file from an alternate location
        copy %sharedToolsPath%\%exMergeEXE% &quot;%exchangeBinFolder%\&quot;
        IF ERRORLEVEL 1 (
        echo Can not seem to find %sharedToolsPath%\%exMergeEXE%
        echo Exiting the batch file
        GOTO EOF
        )
        IF ERRORLEVEL 0 (
        echo Successfully copied %exMergeEXE% into %exchangeBinFolder%
        echo Continuing to next step
        )
        )

        :: Check to see if the local ADModify folder exists. Tries to create it
        IF /I NOT EXIST %exportFolder%\%adModifyToolPath% (
        echo Error: The %exportFolder%\%adModifyToolPath% folder does not exist
        echo Trying to create it
        mkdir %exportFolder%\%adModifyToolPath%
        )

        :: A second check check to see if the local ADModify folder exists. Dies if it doesn't exist.
        IF /I NOT EXIST %exportFolder%\%adModifyToolPath% (
        echo Error: The %exportFolder%\%adModifyToolPath% folder does not exist
        echo Please edit this file and set the adModifyToolPath variable
        GOTO EOF
        )

        :: Check to see if ADModcmd.exe is in the local ADModify folder. Tries to grab from an alt location
        IF /I NOT EXIST %exportFolder%\%adModifyToolPath%\%adModifyToolEXE % (
        echo Error: The %adModifyToolEXE% was not found in %exportFolder%\%adModifyToolPath%
        echo Trying to copy the file from an alternate location
        copy %sharedToolsPath%\%adModifyToolPath% %exportFolder%\%adModifyToolPath%
        IF ERRORLEVEL 1 (
        echo Can not seem to find %sharedToolsPath%\%adModifyToolPath%\%adModifyTool EXE%
        echo Exiting the batch file
        GOTO EOF
        )
        IF ERRORLEVEL 0 (
        echo Successfully copied %adModifyToolEXE% and required files into %exportFolder%\%adModifyToolPath%
        echo Continuing to next step
        )
        )

        :: Check to see if the exportSettingFile file exists. If true, remove it
        IF /I EXIST %exportFolder%\%exportSettingFile% (
        echo Removing old %exportFolder%\%exportSettingFile% file
        del %exportFolder%\%exportSettingFile%
        )

        :: Check to see if the exportMailBoxFile file exists. If true, remove it
        IF /I EXIST %exportFolder%\%exportMailBoxFile% (
        echo Removing old %exportFolder%\%exportMailBoxFile% file
        del %exportFolder%\%exportMailBoxFile%
        )

        :: Check to see if the renamed exportPST file exists. If true, dies to avoid overwriting it
        IF /I EXIST %exportFolder%\%exportUserName%-existing-file-renamed-on-%thisMonth%-%thisDay%-%thisYear%.PST (
        echo Error: Found an existing renamed version of the exported file
        echo Please clean up these files and rerun
        GOTO EOF
        )

        :: Check to see if the exportPST file already exists. If true, renames it
        IF /I EXIST %exportFolder%\%exportUserName%.PST (
        echo Renaming old %exportFolder%\%exportUserName%.PST file
        rename %exportFolder%\%exportUserName%.PST %exportUserName%-existing-file-renamed-on-%thisMonth%-%thisDay%-%thisYear%.PST
        )

        :: Grant the current admin full rights to the User Mailbox using ADModify
        echo Giving %adDomainName%\%adminUserName% full rights to %exportUserName% mailbox
        %exportFolder%\%adModifyToolPath%\%adModifyToolEXE % -dn %adBaseDN% -f %adLDAPFilter% %adModifyToolOptions% %adModifyToolAddAccess% %adDomainName%\%adminUserName% %adModifyToolAddAccessMask%

        :: Write the required files

        :: Exported Mailboxes Files which contains the fully qualified legacyExchangeDN name
        echo Writing Mailbox file
        echo %legacyExchangeDN%&gt;&gt; %exportFolder%\%exportMailBoxFile%

        :: Exchange Merge Utility Settings File (with only the required settings)
        echo Writing ExMerge Settings File
        echo [EXMERGE]&gt;&gt; %exportFolder%\%exportSettingFile%
        echo LoggingLevel=%exportLoggingLevel% &gt;&gt; %exportFolder%\%exportSettingFile%
        echo LogFileName=%exportFolder%\%exportLogFile%&gt;&gt; %exportFolder%\%exportSettingFile%
        echo DataDirectoryName=%exportFolder%&gt;&gt; %exportFolder%\%exportSettingFile%
        echo SourceServerName=%exchangeServerName%&gt;&gt; %exportFolder%\%exportSettingFile%
        echo FileContainingListOfMailboxes=%exportFolder%\%expo rtMailBoxFile%&gt;&gt; %exportFolder%\%exportSettingFile%

        :: Run the export using the files we just wrote
        echo Exporting Email
        &quot;%exchangeBinFolder%\%exMergeEXE%&quot; -B -F %exportFolder%\%exportSettingFile%

        :: Opens the export log file in notepad
        start %textViewerApplication% %exportFolder%\%exportLogFile%

        :: Remove the admins full rights to the User Mailbox using ADModify
        echo Removing %adDomainName%\%adminUserName% full rights to %exportUserName% mailbox
        %exportFolder%\%adModifyToolPath%\%adModifyToolEXE % -dn %adBaseDN% -f %adLDAPFilter% %adModifyToolOptions% %adModifyToolRemoveAccess% %adDomainName%\%adminUserName% %adModifyToolRemoveAccessMask%

        :: Clean up the exportMailBoxFile and exportSettingFile if debugging in not enabled
        IF NOT %debugEnabled%==1 (
        del %exportFolder%\%exportMailBoxFile%
        del %exportFolder%\%exportSettingFile%
        )

        :: Clean up the local copy of ADModify
        IF /I EXIST %exportFolder%\%adModifyToolPath% (
        echo Removing %exportFolder%\%adModifyToolPath% folder
        rmdir /S /Q %exportFolder%\%adModifyToolPath%
        )

        :EOF
        echo Done!
        </pre></div></div></div></div>

        [This message has been edited by Evan.Waite (edited 12-01-2005).]

        [This message has been edited by Evan.Waite (edited 12-01-2005).]
        </div></div>

        Comment

        Working...
        X
        😀
        🥰
        🤢
        😎
        😡
        👍
        👎