Home Outlook How to Batch Extract Attachments from MSG Files Using PowerShell?

How to Batch Extract Attachments from MSG Files Using PowerShell?


If you want to extract multiple attachments from the MSG file but you don’t want to spend a single penny. Then you are landed on the right page because here we are going to discuss a solution on how to batch extract attachment from MSG file using PowerShell

Basically, PowerShell is a cross-platform task automation management framework. It uses a command-line shell and scripting language. Generally, it is used for tedious or time-consuming tasks. Hence, using the PowerShell script we will try to provide the best solution that makes the tedious attachments extraction process a fun game.

Quick Solution

If you want to extract batch attachments from the MSG file, then you can try SysTools Outlook Attachment Extractor toolkit. The tool gives the surety for no data loss during the whole process. And save multiple attachments from Outlook emails, contact, calendar, task, journals.

Outlook Attachment Extractor

How to Batch Extract Attachments from MSG Files Using PowerShell?

To download attachments from the MSG file using PowerShell follow the below steps carefully. Because any mistakes can be the reason for data loss. Also, the following method contains programming tasks so don’t skip any steps.

  • First, open any Code Editor like Notepad++ or simply you can open Notepad
  • Now, copy and paste the below script on the Code editor

function Expand-MsgAttachment

[Parameter(ParameterSetName=”Path”, Position=0, Mandatory=$True)]

[Parameter(ParameterSetName=”LiteralPath”, Mandatory=$True)]

[Parameter(ParameterSetName=”FileInfo”, Mandatory=$True, ValueFromPipeline=$True)]

# Load application
Write-Verbose “Loading Microsoft Outlook…”
$outlook = New-Object -ComObject Outlook.Application

switch ($PSCmdlet.ParameterSetName)
“Path” { $files = Get-ChildItem -Path $Path }
“LiteralPath” { $files = Get-ChildItem -LiteralPath $LiteralPath }
“FileInfo” { $files = $Item }

$files | % {
# Work out file names
$msgFn = $_.FullName

# Skip non-.msg files
if ($msgFn -notlike “*.msg”) {
Write-Verbose “Skipping $_ (not an .msg file)…”

# Extract message body
Write-Verbose “Extracting attachments from $_…”
$msg = $outlook.CreateItemFromTemplate($msgFn)
$msg.Attachments | % {
# Work out attachment file name
$attFn = $msgFn -replace ‘\.msg$’, ” – Attachment – $($_.FileName)”

# Do not try to overwrite existing files
if (Test-Path -literalPath $attFn) {
Write-Verbose “Skipping $($_.FileName) (file already exists)…”

# Save attachment
Write-Verbose “Saving $($_.FileName)…”

# Output to pipeline
Get-ChildItem -LiteralPath $attFn

Write-Verbose “Done.”

  • After that save the file name with MsgUtility.psm1
  • Now save the file in MsgUtility folder under PowerShell modules folder
  • Follow the location to find the PowerShell modules folder in windows 10


  • If the PowerShell modules folder does not exist then simply create it
  • Now, import the new modules and run Expand-MsgAttachment

Import-Module MsgUtility
Expand-MsgAttachment *

Limitations of The PowerShell Modules

  • The PowerShell script for attachments extraction is only for technical users. Non-technical users are not able to use this method.
  • If there any mistake happens then you may lose your data.
  • The PowerShell method consists of a programming task that takes time and makes this task a time-consuming process.
  • Not able to modify the MSG attachments extraction process

Best Way to Batch Extract Attachments from MSG Files

As we said above the PowerShell method is not made for everyone because of its complicity. So in this situation, you can try the automated method. The attachment management utility can easily extract any number of attachments from Outlook OST, PST, MSG, and BAK files.

Outlook Attachment Extractor

The tools provide various advanced features to modify the extraction process as per your requirements. The tool is capable to maintain folder hierarchy and data integrity. It comes with various filter options such as date filter, size filter, file extension filter, and category filter.

Step to Batch Extract Attachments from MSG Files Using Tool

1. Download and install the software

2. After installation is done choose the MSG radio button. And then click on the Add File(s) or Add Folder option to add the MSG file

3. Choose the Maintain Folder Hierarchy option to preserve the folder structure

4. Click on the Change button to select the destination location

5. Select Email option from Select Item Types

6. After all the settings click on the Extract button to start the process.


As said above there are many users who don’t want to spend money to extract attachments. So they seeking the freeway to download attachments from Outlook. So, here in this article, we have discussed the best free solution on how to batch extract attachments from MSG files using PowerShell. In addition, if you don’t want to spend your time in some time-consuming process then you can try an automated solution too that is mentioned above.