Rammy Charles
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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'
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')
For that specific feature EWS will also accomplish this using folder operations:
Same link as provided above from Sir Bounty
http://msdn.microsoft.com/en-us/library/office/dd877045(v=exchg.140).aspx
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
ASKER
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
[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.
The search mailbox cmdlet will take subject keywords etc but you are not able to specify the subfolder.
ASKER
We do not want to use a retention policy as a lot of these requests are one offs.