Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Exchange 2010 sp1 -Purge a single subfolder

Posted on 2012-09-21
8
Medium Priority
?
1,728 Views
Last Modified: 2013-01-10
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.....
0
Comment
Question by:Tencha
  • 3
  • 2
6 Comments
 
LVL 4

Assisted Solution

by:johan_v
johan_v earned 1000 total points
ID: 38424143
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
 

Author Comment

by:Tencha
ID: 38491605
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
 
LVL 40

Accepted Solution

by:
Subsun earned 1000 total points
ID: 38564227
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
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

 

Author Comment

by:Tencha
ID: 38622756
I'm tweaking it, but have not finished it. I will try within the next two weeks.
0
 

Author Comment

by:Tencha
ID: 38742478
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
 
LVL 40

Expert Comment

by:Subsun
ID: 38742479
Didn't my comments answer your queries?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post, we will learn to set up the Group Naming policy and will see how it is going to impact the Display Name and the Email addresses of the Group.
Upgrading from older Exchange server to the latest Exchange server can be tiresome, error-prone and risky, without being a seasoned exchange server administrators. It can become even problematic if you're an organization that runs on tight timeline…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question