Solved

Exchange 2010 Power Shell script delete content issue

Posted on 2013-01-31
3
1,178 Views
Last Modified: 2013-07-25
As a result of trying to do 15 things at once and not paying closer attention to my cmd line syntax, I made a little booboo.

Goal: To delete all of my messages in my Deleted Items on the 2010 Exchange server using Exchange Power Shell (PS). That's it! No more, no less.

Syntax used:  Search-Mailbox -Identity "Peter Mitchell" -TargetFolder "\DeletedItems" -LogLevel Full -DeleteContent
TargetMailbox: ITSupport

Issue: Being used to syntax in Exchange 2007, I had what I thought was the correct syntax for 2010. However as a result of assumption and not paying close, undivided attention I did not.

Result: My entire Inbox/subfolders and calendar wiped out clean. Not my intention for that to happen as the intention was to ONLY delete the items from my Deleted Items folder.
From there, and as I inadvertently instructed the PS to do, it moved all of my Inbox/subfolders to the ITSupport mailbox and created a new folder called "\DeletedItems" (which I know have learned I inadvertently instructed it to do!). The full path was actually "\DeletedItems\Peter Mitchell-1/31/2013 5:51:16 PM\Primary Mailbox\[Calendar, Contacts,Deleted Items,Drafts,Inbox,Recoverable Items,Sent ITems,Suggested Contacts,SyncIssues,Tasks]  (listed in folder tree under Primary Mailbox)

Magic question is....where did I go so wrong? (aside from excessively multi-tasking!)?  And what is the correct Exchange PS cmd line syntax to just delete messages from a given folder in a given mailbox?

Any help would be greatly appreciated for this valuable lesson learned!
0
Comment
Question by:goodwill1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 5

Assisted Solution

by:coraxal
coraxal earned 250 total points
ID: 38842046
The cmdlet you're looking for is:  Export-Mailbox with the "-IncludeFolder" parameter
Export-Mailbox -Identity "Mailbox Name" -IncludeFolder "\Deleted Items" -DeleteContent

Open in new window

0
 
LVL 16

Accepted Solution

by:
Rajitha Chimmani earned 250 total points
ID: 38842509
The mistake that you did was "you did not specify any folders from which emails must be deleted and hence all emails were deleted"

With search-mailbox command you can only delete emails from entire mailbox.

You need to use Export-mailbox to delete items from specific folders.

Export-Mailbox "Peter Mitchell" -TargetMailbox "ITSupport" -TargetFolder "Mitchell" -IncludeFolders "\DeletedItems" -DeleteContent
0
 

Author Closing Comment

by:goodwill1
ID: 39355063
Thank you!
0

Featured Post

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

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

This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
This article explains how to install and use the NTBackup utility that comes with Windows Server.
In this video we show how to create a Resource Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: Navigate to the Recipients >> Resources tab.: "Recipients" is our default selection …
To show how to create a transport rule in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Mail Flow >> Rules tab.:  To cr…

734 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