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.
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.”
—————————————————-
powershell: Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
3. Type “Y” to confirm
powershell: cd “C:\Path\To\ScriptFolder”
powershell: .\ProcessPSTFiles.ps1
C:\Output\MSG files\File1\
containing the MSG files for File1.pst
.C:\Output\MSG files\File2\
containing the MSG files for File2.pst
.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.