nicholab Posted October 26, 2017 Posted October 26, 2017 How do i delete an email from office 365 I need to remove an email sent to most users?
AngryITGuy Posted October 26, 2017 Posted October 26, 2017 Although I’ve never had to do this, I have practised the procedure should I ever be required to delete an email sent to all users in our tenant. I followed the instructions outlined here to delete an email from user mailboxes using PowerShell https://technet.microsoft.com/en-us/library/ff459253(v=exchg.150).aspx 1
MicrodigitUK Posted October 26, 2017 Posted October 26, 2017 PowerShell Script for office365: #This script will take take a user-imputed subject to delete Messages from #Every mailbox within the Organisation #ARGS [string]$decision = "n" Write-Host "This script requires the `"Discovery Management`" Exchange Role-Group PLUS `"Mailbox Import Export`" Role assigned to your Exchange onlineAdmin Account `nPlease add it before proceeding:" Write-Host "`n`nEnter Administration Credentials" $LiveCred = Get-Credential #Pass Creds to Outlook.com and generate PS Session $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection #Import PS Session/Grab MSOL Cmdlets Import-PSSession $Session $Subject = Read-Host "Please Enter a Message Subject to be deleted from ALL mailboxes:" $decision = Read-Host "Are you sure youi want to delete messages with the subject " $Subject " (Y/N)?" if ($decision -eq "y") { Write-Host "Deleting" $Subject Get-Mailbox -ResultSize unlimited | Search-Mailbox -SearchQuery "subject:$Subject" -DeleteContent -Confirm } else { Write-Host "Nothing deleted" } Remove-PSSession $Session CD .. Write-Host "Connection to MSOL closed" Using the Search-Mailbox cmd with the DeleteContent switch requires that the admin account be added to the Discovery Management and Mailbox Import Export group. If this is the situation, please go to the EAC (Exchange admin center) > permissions > admin roles to add your account into the corresponding groups to see if there is any improvement. Warning: Use the above script with caution; When using the DeleteContent parameter, messages are permanently deleted from the user’s mailbox and cannot be recovered. (It could also take some time to run over a big Office365 Tenant) For a full list of -SearchQuery parameters go here https://technet.microsoft.com/en-us/library/jj983804.aspx 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now