Link to home
Start Free TrialLog in
Avatar of Tencha
Tencha

asked on

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.....
SOLUTION
Avatar of johan_v
johan_v
Flag of Netherlands 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 Tencha
Tencha

ASKER

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) } }
ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India 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 Tencha

ASKER

I'm tweaking it, but have not finished it. I will try within the next two weeks.
Avatar of Tencha

ASKER

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
Didn't my comments answer your queries?