-
-
Save davidphasson/100840 to your computer and use it in GitHub Desktop.
Dump exchange databases to pst files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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