With an occasional need to export a user mailbox to PST for archive, I decided it would be useful to be able to call up a script and save myself some time and mouse clicking.
Should you wish to give the script below a try, copy it into a text file and change the extension to .ps1
Note: This script should be run from a system with Outlook and the Exchange Management Tools installed (they both need to be 32 or 64-bit) for this to work).
rem Gathering names for labeling the exported PST
$fname = Read-Host "First name?"
$lname = Read-Host "Last name?"
rem Assigning the current date to the $date variable
$date = get-date -uformat "%Y_%m_%d"
rem Capturing name of mailbox account (assigning to $uname variable)
$uname = Read-Host "Username?"
rem Capturing admin acct that is currently logged in to add mailbox permissions (assigning to $admin variable)
whoami > $admin
rem Adding permissions for admin allowing export
Add-MailboxPermission -AccessRights FullAccess -Identity $uname -User $admin
rem Exporting mailbox to D:\PSTs (change path to your liking)
Export-Mailbox -Identity $uname -PSTFolderPath D:\PSTs\$fname"_"$lname"_"$date.pst
If at some point I get time or get paid to do so, I'll make a script to allow the use of a list for mass export.
No comments:
Post a Comment