Skip to content

Instantly share code, notes, and snippets.

@davidphasson
Forked from anonymous/gist:100838
Created April 23, 2009 23:34
Show Gist options
  • Save davidphasson/100840 to your computer and use it in GitHub Desktop.
Save davidphasson/100840 to your computer and use it in GitHub Desktop.
Dump exchange databases to pst files
# Script for dumping exchange database to .pst files.
# Globals
$Now = Get-Date
$Days = "7"
$TargetFolder = "C:\Users\jtrout\"
$LastWrite = $Now.AddDays(-$days)
$Files = get-childitem $TargetFolder -include *.pst -recurse | Where {$_.LastWriteTime -le "$LastWrite"}
# Create Dir for Backup and set the path.
$Pst = "$TargetFolder$((get-date).toString('MMdd'))"
md $Pst
# Dump the mailboxes to the proper folder.
Get-Mailbox | Export-Mailbox -PSTFolderPath $Pst
# Remove .pst files older than a week.
foreach ($File in $Files)
{write-host "Deleting File $File" -foregroundcolor "Red"; Remove-Item $File | out-null}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment