Link to home
Start Free TrialLog in
Avatar of Rammy Charles
Rammy CharlesFlag for United States of America

asked on

PowerShell script for deleting old messages from specific folder Exchnage 2010

I am looking for a powershell script to deleted messages from a user's mailbox that targets messages older than 'x' number of days within a specific folder (inbox or deleted items). Can somebody assist with the script?
SOLUTION
Avatar of becraig
becraig
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Rammy Charles

ASKER

Thanks. How would I target or specify a specific folder?

We do not want to use a retention policy as a lot of these requests are one offs.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks but is there a way to specify a specific subfolder in the user mailbox?
If that was to me, yes, absolutely.
I use this to cleanup a subfolder of the inbox...

I just use this for our 'Archive Folder'
$SearchFilter = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.FolderSchema]::DisplayName,'Archive Folder')

Open in new window

For that specific feature EWS will also accomplish this using folder operations:
Folder Operations

The Folder operations provide access to folders in the Exchange data store. A client application can create, update, delete, copy, find, get, and move folders that are associated with a mailbox user. Folders are used to gain access to items in the store, and provide a reference container for items in the store.

Same link as provided above from Sir Bounty
 http://msdn.microsoft.com/en-us/library/office/dd877045(v=exchg.140).aspx
There is now way to specify a folder just using the Exchange Management shell? This below script would be ideal if I can specify the folder

[DateTime]$Today = (Get-Date).adddays(-30)
Search-Mailbox -Identity "Starr, Ringo" -SearchQuery "Received:> $($Today) and Received:(Today) and subject:Strawberry" -DeleteContent -force
Sadly no :~(

The search mailbox cmdlet will take subject keywords etc but you are not able to specify the subfolder.