Exchange 2010 sp1 -Purge a single subfolder

Exchange 2010 SP1 Purge

I want to purge a sub-folder from a users "inbox " and then from the "purge" folder.

I've tried the search query and can not seem to get it to work. I do not have information such as "From or Subject" . In the past I have used the following to delete single items. I've also used MFCMapi

  I run the follow exshell  
1.get-mailbox <user> | search-mailbox -searchquery "From:'xxx@xxx.com'" -deletecontent -searchdumpsteronly -Force

2.just in case...
get-mailbox <user> | search-mailbox -searchquery "From:'xxx@xxx.com'" -deletecontent -searchdumpster -Force  

Then I do a search to make sure...

3.
get-mailbox <user> | search-mailbox -searchquery "From:'xxx@xxx.com'"
 -searchdumpsteronly -Targetmailbox "Discovery search Mailbox -Targetfolder "Inbox"

I am trying to avoid deleting the dumpster altogether.

Exchange 2010 Sp1 Win2K8 R2
I have a CAS Arrey with a DAG set up.....
TenchaAsked:
Who is Participating?
 
SubsunCommented:
If you haven't already got the answers..

1. I would change this:  'name@mailbox'

Replace with the mailbox which you want to access..

2. We are now running Exchange SP2 on the CAS array....Change this to reflect "2"?

Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1)

Change to Exchange2010_SP2

3. The folder to be deleted, change here?
 if($folder.DisplayName -eq "Foldertobedeleted")

yes

4. Can I change soft delete to hard delete?
    $folder.delete([Microsoft.Exchange.WebServices.Data.DeleteMode]::SoftDelete) } }

Yes you can use HardDelete

5. Do I save as .ps1?

Yes

6.Do I run it from Mailbox server, Cas server or my PC powershell 2.0 with exchange module ?

You can run it from any computer where you have installed Exchange Web Services Managed API  and PowerShell. Make sure you are able to access the exchange server from the computer which you are running this script..
0
 
johan_vCommented:
Hi,

You can do this by using an ews. Script:

$MailboxName = 'Name@Mailbox'
$dllpath = "D:\EWS\Microsoft.Exchange.WebServices.dll"
[void][Reflection.Assembly]::LoadFile($dllpath)
$Service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1)
$Service.AutodiscoverUrl($MailboxName,{$true})
$RootFolderID = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Root,$MailboxName)
$RootFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($Service,$RootFolderID)
$FolderView = New-Object Microsoft.Exchange.WebServices.Data.FolderView(1000)
$FolderView.Traversal = [Microsoft.Exchange.WebServices.Data.FolderTraversal]::Deep
$Response = $RootFolder.FindFolders($FolderView)
ForEach ($Folder in $Response.Folders) {
  if($folder.DisplayName -eq "Foldertobedeleted") {
    $folder.delete([Microsoft.Exchange.WebServices.Data.DeleteMode]::SoftDelete) } }

A great source for this kind of stuff is Glenn Scales website:

http://gsexdev.blogspot.nl/

Regards,
Johan
0
 
TenchaAuthor Commented:
I"m still new at scripting and the basics, so excuse the basic questions. In what you provided, thank you first of all. What would I  change to match what I need...


1. I would change this:  'name@mailbox'


2. We are now running Exchange SP2 on the CAS array....Change this to reflect "2"?

Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1)

3. The folder to be deleted, change here?
 if($folder.DisplayName -eq "Foldertobedeleted")

4. Can I change soft delete to hard delete?
    $folder.delete([Microsoft.Exchange.WebServices.Data.DeleteMode]::SoftDelete) } }

5. Do I save as .ps1?

6.Do I run it from Mailbox server, Cas server or my PC powershell 2.0 with exchange module ?

Thank you again!!!!!!!!!!!!




$MailboxName = 'Name@Mailbox'
$dllpath = "D:\EWS\Microsoft.Exchange.WebServices.dll"
[void][Reflection.Assembly]::LoadFile($dllpath)
$Service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1)
$Service.AutodiscoverUrl($MailboxName,{$true})
$RootFolderID = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Root,$MailboxName)
$RootFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($Service,$RootFolderID)
$FolderView = New-Object Microsoft.Exchange.WebServices.Data.FolderView(1000)
$FolderView.Traversal = [Microsoft.Exchange.WebServices.Data.FolderTraversal]::Deep
$Response = $RootFolder.FindFolders($FolderView)
ForEach ($Folder in $Response.Folders) {
  if($folder.DisplayName -eq "Foldertobedeleted") {
    $folder.delete([Microsoft.Exchange.WebServices.Data.DeleteMode]::SoftDelete) } }
0
Live Q & A: Securing Your Wi-Fi for Summer Travel

Traveling this summer? Join us on June 18, 2018 for a live stream to learn about the importance of Wi-Fi security and 3 easy measures you can start taking immediately to protect your private data while using public Wi-Fi. Follow us today to learn more!

 
TenchaAuthor Commented:
I'm tweaking it, but have not finished it. I will try within the next two weeks.
0
 
TenchaAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for Tencha's comment #a38491605

for the following reason:

Great detail
0
 
SubsunCommented:
Didn't my comments answer your queries?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.