If you want to reduce mailbox size by deleting large attachments, you have one option if using new Outlook or Outlook on the web: permanently delete the message. If you have classic Outlook, you can open the message and remove the attachment then save and close the message. If you have a lot of attachments to remove, it can take a while to clean up.
Or you can use PowerShell (or VBA, but PowerShell doesn't require changing macro security settings.)
I have two versions of a PowerShell script to remove attachments. The first runs on all messages in the selected folder and removes attachments larger than approximately 1 MB. The second one runs on the selected messages and removes all attachments from those messages.
Remove large attachments from all messages in selected folder
This script removes large attachments (over approximately 1 MB) from the all messages in the selected folder. As written, it saves the attachments before deleting them from the message. You can remove the lines that save the attachments or change the file size.
Before running it, make sure you have the desired folder selected!
clear $olApp = New-Object -ComObject Outlook.Application $Mailfolder = ($olApp.ActiveExplorer()).CurrentFolder write-host $mailfolder.name $Items = $Mailfolder.Items ## Set the path if saving / remove if not saving $AttachmentPath = "C:\Outlook\Attachments\" if (!(Test-Path -Path $AttachmentPath)) { New-Item -ItemType Directory -Path $AttachmentPath } write-host $AttachmentPath ## End set path foreach ($email in $Items) { $attcount = $email.Attachments.count write-host $attcount foreach ($Attachment in $email.Attachments) { if ($attcount -ge 1) { $AttachmentIndex = 1 write-host $Attachment.size, $Attachment.FileName ## if greater than 1 MB if ($Attachment.size -ge 1049000) { ## remove this block if you don't want to save a copy $AttachmentFileName = $AttachmentPath + $Attachment.FileName write-host $AttachmentFileName while(Test-Path -Path $AttachmentFileName){ $AttachmentFileName = $AttachmentPath +$AttachmentIndex+"-" + $Attachment.FileName $AttachmentIndex++ } $Attachment.SaveAsFile($AttachmentFileName) ## end remove if not saving #This line deletes the attachment $Attachment.delete() } } if ($attcount -ge 0) { $Attachment.delete() } } }
Remove attachments from selected messages
This script removes all attachments from the selected messages. As written, it saves the attachments before deleting them from the message. You can remove the lines that save the attachments.
clear $olApp = New-Object -ComObject Outlook.Application $currentExplorer = ($olApp.ActiveExplorer()) $Selection = $currentExplorer.Selection write-host $Selection.count ## remove if not saving attachments $AttachmentPath = "C:\Outlook\Attachments\" if (!(Test-Path -Path $AttachmentPath)) { New-Item -ItemType Directory -Path $AttachmentPath } # end remove foreach ($email in $Selection) { write-host $email.subject $attcount = $email.Attachments.count write-host $attcount foreach ($Attachment in $email.Attachments) { if ($attcount -ge 1) { $AttachmentIndex = 1 ## remove if not saving attachment $AttachmentFileName = $AttachmentPath + $Attachment.FileName while(Test-Path -Path $AttachmentFileName){ $AttachmentFileName = $AttachmentPath +$AttachmentIndex+"-" + $Attachment.FileName $AttachmentIndex++ } $Attachment.SaveAsFile($AttachmentFileName) # end remove if not saving attachment $Attachment.delete() } if ($attcount -ge 0) { $Attachment.delete() } } }
Using PowerShell Scripts
To use these PowerShell scripts with classic Outlook, start typing PowerShell on the start menu and open Windows PowerShell when it comes up. Windows PowerShell ISE has a script pane at the top (click the V on the right if the script pane is not visible), which is useful if you want to edit the script.
Paste the entire script in the PowerShell window and press Enter or the Run button if using PowerShell ISE.
Note: PowerShell scripts will not work with new Outlook or Outlook on the web.
Saving PowerShell Scripts
If you want to save the script as a .ps1 file, paste it into Notepad and save it with the extension .ps1. To open it in the PowerShell IDE, type PowerShell on the start menu and click on Windows PowerShell IDE when the PowerShell app is found. Paste the script in the editing window.
To use it, you need to allow local scripts by running this command:
Set-ExecutionPolicy RemoteSigned
To run your saved .ps1 file, right-click on the script and choose Run with PowerShell.