Search For A Solution!

Total Pageviews

Thursday, April 11, 2013

Exchange: Automated Mailbox Cleanup / Scheduled Task

Steps:

1. Setup a directory on your exchange server C:\Scripts for easy access and creating all below files

2. Create a txt file or files with the mailbox(es) you want to cleanup. Multiple can be used for running diff scheduled tasks basis each or groups of mailboxes.
* You can use Get-mailbox to get the complete list and then chose
ex. BBs.txt and then enter the mailbox name, one per line and save
ex.
ITalerts
Finance
a
3. Create the txt file with the command ps1 to be called at the next step.
Open notepad and copy/paste below and give a descriptive name such as ITalerts.ps1

Get-Content C:\_Scripts\BBs.txt| Export-Mailbox -ExcludeFolders "\Contacts" -DeleteContent -confirm:$false


*Above will empty all messages from mailbox(es) inside the BBs.txt but will exclude the contacts and wont request for confirm to proceed with deletion

4. Create a bat file and copy below command:

C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\bin\exshell.psc1" -command ". 'C:\_Scripts\yourfilename.ps1'"

Where in red should point to correct name you gave to your ps1 command.

Now you can go to task scheduler and create when and how often you need the mailboxes emptied.

No comments:

Post a Comment