PowerShell Script to Export Exchange 2013 PSTs
From DFWLPiki
Overview
This script can allow you to create a scheduled job to dump all Mailboxes on a server to .pst files, each time they are dumped they are put into a directory that is named after the date the script is run.
New-ManagementRoleAssignment –Role “Mailbox Import Export” –User [DOMAIN]\Username Get-MailboxExportRequest -Status Completed | Remove-MailboxExportRequest -confirm:$all $BackupPath = "F:\PSTs" $MaxDays = "-30" $CurrentDate = Get-Date $DeleteDate = $CurrentDate.AddDays($MaxDays) # Delete the files older than x days on the main folder level (Folders Excluded) Get-ChildItem $BackupPath | ?{ !$_.PsIsContainer } | Where-Object { $_.LastWriteTime -lt $DeleteDate } | Remove-Item -Force -Confirm:$False # Delete the folders (and all included content) older than x days on the main folder level (Files Excluded) Get-ChildItem $BackupPath | ?{ $_.PSIsContainer } | Where-Object { $_.LastWriteTime -lt $DeleteDate } | Remove-Item -Recurse -Force -Confirm:$False $Folder = $(get-date -f yyyy-MM-dd) MkDir F:\PSTs\$Folder foreach ($i in (Get-Mailbox)) { New-MailboxExportRequest -Mailbox $i -FilePath "\\[UNCPath]\F$\PSTs\$Folder\$($i.Alias).pst" } Get-MailboxExportRequest -Status Completed | Remove-MailboxExportRequest -confirm:$all