Script for deleting items from the Deleted items folder older than 60 days

Hi guys, I'm after a power-shell script (not retention policies) to action the following for a specific user please:

Script for deleting items from the Deleted items folder older than 60 days

Running Exchange 2010 SP3

Thanks
SandyFrankAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SandyFrankAuthor Commented:
Thank you but Ive already seen that, that only applies the tag to newly deleted items which we have in place already. I want to delete items that were there before the retention policies have been in place which was a week ago.

So again, would just like to delete items from the Delete Items folder that are x amount of days old using Power-Shell. Anyone else know?

Thanks
0
Kanti PrasadCommented:
Hi

Just see if this what you are looking for


1.Grant user full mailbox access to all mailboxes on the Exchange server:

Get-Mailbox -Server %ServerName%| Add-MailboxPermission -User yourusername -AccessRights FullAccess

2.This cmdlet will delete all deleted items older than the mentioned date from the mailbox Simon:

Export-Mailbox -Identity Sam -IncludeFolders “\Deleted Items” -StartDate “3/22/2013″ -EndDate “10/15/2013″ –DeleteContent

3.Now, if we need to perform this on a set of mailboxes, paste all display name’s to a TXT file, name is as “deletemail.txt”. Then navigate to that folder in powershell and run:

Get-Content deletemail.txt | Export-Mailbox -IncludeFolders  “\Deleted Items” -StartDate “3/22/2013″ -EndDate “06/15/2013″ –DeleteContent –Maxthreads 4
0
How do you know if your security is working?

Protecting your business doesn’t have to mean sifting through endless alerts and notifications. With WatchGuard Total Security Suite, you can feel confident that your business is secure, meaning you can get back to the things that have been sitting on your to-do list.

SandyFrankAuthor Commented:
I'm afraid Export-mailbox doesn't work with Exchange 2010 SP3


[PS] C:\Windows\system32>Export-Mailbox -Identity aqureshi -IncludeFolders "\Deleted Items" -StartDate "3/22/2015? -EndDate "6/28/2015" -DeleteContent

Export-Mailbox : The term 'Export-Mailbox' is not recognized as the name of a cmdlet, function, script file, or operabl
e program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:15
+ Export-Mailbox <<<<  -Identity aqureshi -IncludeFolders "\Deleted Items" -StartDate "3/22/2015? -EndDate "6/28/2015?
-DeleteContent
    + CategoryInfo          : ObjectNotFound: (Export-Mailbox:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
0
Kanti PrasadCommented:
Hi

Can you reconfirm that you want to delete items older than the mentioned date from  a mailbox say Sam ?

now try to
        copy the below code into a notepad
         change  -Identity Sam to the mailbox name you want instead of Sam
          search for ConfigurationManager.psd1 and replace the path fromE:\ ... to your CM path
         save as say    yourfilename.ps1
         run it on PS>
                     .\yourfilename.ps1

Process
{
#--------------------
#   Change the path
    $CMModule='E:\ConfigMgr\AdminConsole\bin\ConfigurationManager.psd1'

#----
    Import-Module $CMModule
 
    {
        Export-Mailbox -Identity Sam -IncludeFolders “\Deleted Items” -StartDate “3/22/2013″ -EndDate “10/15/2013″ –DeleteContent
           
    }
}
0
SandyFrankAuthor Commented:
I don't have ConfigurationManager.psd1 anywhere. This is a Server 2012 server with Exchange 2010 SP3 and all prerequisites installed.
0
Kanti PrasadCommented:
Hi

From which box\server you are running your Powershell?

Maybe wait for some other expert to respond if  there are other alternatives.

To run a few cmdlet commands you need  SCCM Console installed  .

https://social.technet.microsoft.com/Forums/en-US/524ef8a9-9add-4dcf-9d89-2fb7820e5d0f/powershell-cannot-connect-to-sccm-site-drive-when-not-in-console?forum=configmanagersecurity
0
Will SzymkowskiSenior Solution ArchitectCommented:
Export-Mailbox -Identity aqureshi -IncludeFolders "\Deleted Items" -StartDate "3/22/2015? -EndDate "6/28/2015" -DeleteContent

The askers stated that he is using Exchange 2010. Export-mailbox is used in Exchange 2007 and you cannot use -deletecontent switch in Exchange 2007 without specifying a PSTFile path or another Target Mailbox.

Use the below command to accomplish this. Also you first need to grant yourself permissions

Grant yourself permission
New-ManagementRoleAssignment -Role "Mailbox Import Export" -User Administrator

Open in new window


In Exchange you can use the Search-Mailbox cmdlet but you cannot specific a Subfolder unfortuntately. Below are two scripts one for a single mailbox and another for all mailboxes.

Single Mailbox
Search-Mialbox -Identity User1 -SearchQuery "*Hello*" -StartDate "05/02/2015" -deletecontent

Open in new window


Multiple Mailboxes
Get-Mialbox -ResultSize "unlimited" | Search-Mialbox -SearchQuery "*Hello*" -StartDate "05/02/2015" -deletecontent

Open in new window


You can also reference my HowTo on Exporting Mail from Exchange
http://www.wsit.ca/how-tos/exchange-server-2/export-mailbox-using-exchange-management-shell-200720102013/

Will.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SandyFrankAuthor Commented:
Hi Will Szymkowski thank you for your comment, are you saying there is no way to specify "Deleted Items" folder so I can delete items older than X amount of days.

I'm aware of the script above, again thank you but I get the feeling it's no longer possible to do what I'm asking.
0
Will SzymkowskiSenior Solution ArchitectCommented:
I'm aware of the script above, again thank you but I get the feeling it's no longer possible to do what I'm asking.

Thats is correct. You cannot specify a subfolder using the Search-Mailbox cmdlet. So what you are trying to accomplish exactly will not work. What i have provided is a method to do it for the entire mailbox.

Will.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

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.