How to use PowerShell to Process Multiple PST Files in Aid4Mail with the CLI (Enterprise license)

This guide explains how to automate the processing of multiple PST files located in a single folder using a PowerShell script with Aid4Mail. Since Aid4Mail processes one PST file per session, this script runs the command for each file individually.


Prerequisites

  1. Aid4Mail Installed: Ensure Aid4Mail is installed and the executable (a4m-64.exe or a4m-32.exe) is accessible.
  2. PowerShell Access: You need permission to execute PowerShell scripts on your system.
  3. PST Files Organized: Place all PST files in the same folder for processing.

Step 1: Download or Create the PowerShell Script

Copy the following PowerShell script and save it to a file named: ProcessPSTFiles.ps1

—————————————————-

# Define paths
$sourceFolder = “C:\PST Files”
$targetFolder = “C:\Output\MSG files”
$aid4mailPath = “C:\Program Files (x86)\Aid4Mail5\a4m-64.exe”

# Loop through all PST files in the source folder
Get-ChildItem -Path $sourceFolder -Filter “*.pst” | ForEach-Object {
$pstFile = $_.FullName # Full path of the current PST file
$fileName = $_.BaseName # File name without extension

# Prepare the output folder for this PST file
$outputFolder = Join-Path -Path $targetFolder -ChildPath $fileName
if (!(Test-Path -Path $outputFolder)) {
New-Item -ItemType Directory -Path $outputFolder
}

# Run Aid4Mail for the current PST file
$command = “$aid4mailPath -CLI -Source.Format:MapiPST -Source.FileStore:`”$pstFile`” -Target.Format:MapiMSG -Target.RootLocation:`”$outputFolder`””
Write-Output “Processing $pstFile…”
Start-Process -FilePath $aid4mailPath -ArgumentList $command -Wait

# Log completion
Write-Output “$pstFile has been processed and saved to $outputFolder”
}

Write-Output “All PST files have been processed.”

—————————————————-


Step 2: Configure the Script

  1. Replace the placeholders in the script with the correct paths:
    • $sourceFolder: Path to the folder containing your PST files.
    • $targetFolder: Path where the output MSG files should be saved.
    • $aid4mailPath: Full path to the a4m-64.exe or a4m-32.exe executable.
  2. Save the script.

Step 3: Enable PowerShell Script Execution

  1. Open PowerShell as Administrator.
  2. Run the following command to allow scripts to execute:

powershell: Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

3. Type “Y” to confirm


Step 4: Run the Script

  1. Navigate to the folder where you saved the script:

powershell: cd “C:\Path\To\ScriptFolder”

  1. Execute the script:

powershell: .\ProcessPSTFiles.ps1


Step 5: Verify Output

  • The script will process each PST file in the source folder and save the MSG files in a subfolder under the target folder.
  • Each subfolder is named after the corresponding PST file (without the .pst extension).

Troubleshooting

  1. Script Doesn’t Run:
    • Ensure the paths to a4m-64.exe/a4m-32.exe and folders are correct.
    • Verify the PowerShell execution policy is set to RemoteSigned
  2. Aid4Mail Errors:
    • Review the PowerShell console output for error messages from Aid4Mail.
    • Ensure the PST files are not corrupt.
  3. Debugging:
    • Add “Write-Output” lines in the script to print variables and commands for debugging.

Example Scenario

  • Source Folder: “C:\PST Files” contains: File1.pst and File2.pst.
  • Target Folder: “C:\Output\MSG files” will have:
    • C:\Output\MSG files\File1\ containing the MSG files for File1.pst.
    • C:\Output\MSG files\File2\ containing the MSG files for File2.pst.

Conclusion

This PowerShell script provides a simple and automated way to process multiple PST files using Aid4Mail. By following the steps above, you can efficiently convert all PST files in a folder to MSG format without manually running Aid4Mail for each file.

About Fookes Software

Fookes Software Ltd
La Petite Fin 27
1637 Charmey (en Gruyère)
Switzerland

For over 25 years we have been developing award-winning tools and productivity software. We also have more than 20 years of expertise in the field of email processing and analysis.

Our clients include Fortune 500 companies, government agencies, law firms, universities, and professionals specializing in e-discovery and forensics from around the world.

Your outdated browser! You can download Edge or Chrome or Firefox