Link to home
Start Free TrialLog in
Avatar of SandyFrank
SandyFrankFlag for United States of America

asked on

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
Avatar of Kanti Prasad
Kanti Prasad

Avatar of SandyFrank

ASKER

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
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
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
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
           
    }
}
I don't have ConfigurationManager.psd1 anywhere. This is a Server 2012 server with Exchange 2010 SP3 and all prerequisites installed.
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
ASKER CERTIFIED SOLUTION
Avatar of Will Szymkowski
Will Szymkowski
Flag of Canada 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
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.
SOLUTION
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