Office 365 - Deleting Enterprise Vault Items from Exchange Online Mailboxes

I had a number of Exchange Online mailboxes containing legacy Enterprise Vault items which I need to remove. I managed this with the help of  Michel de Rooij's script on the TechNet gallery (1.72 is the latest version at the time of writing this) - https://gallery.technet.microsoft.com/office/Removing-Messages-by-e0f21615

Also the configuration of a new Role Group within Exchange Online thanks to another of his articles - https://eightwone.com/2014/08/13/application-impersonation-to-be-or-pretend-to-be/





You will need to save the script into a directory ( my example - 
D:\ExchangeMigraiton\EVCleanup\) and also install/copy the EWS dll from the Microsoft Exchange Web Services Managed API 2.2. After you have all this in your directory, from an administrative PowerShell session, change the directory and then execute:

Set-ExecutionPolicy unrestricted

$UserCredential = Get-Credential

(Enter your Office365 admin credentials)

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

Import-PSSession $Session

.\Remove-MessageClassItems.ps1 -Identity Test.User@domain.com -Credentials $UserCredential -Impersonation -Server outlook.office365.com -Verbose -DeleteMode SoftDelete -MessageClass IPM.Note.EnterpriseVault* -ScanAllFolders -MailboxOnly

Comments