Skip to content

Instantly share code, notes, and snippets.

@eugrus
Created December 23, 2025 09:41
Show Gist options
  • Select an option

  • Save eugrus/de759fbce868b51e0d5d57171353168e to your computer and use it in GitHub Desktop.

Select an option

Save eugrus/de759fbce868b51e0d5d57171353168e to your computer and use it in GitHub Desktop.
$outlook = New-Object -ComObject Outlook.Application
$explorer = $outlook.ActiveExplorer()
$selection = $explorer.Selection
if ($selection.Count -eq 0) {
Write-Error "No email selected."
exit
}
$mail = $selection.Item(1)
$PicturesFolder = [Environment]::GetFolderPath("MyPictures")
$savePath = Join-Path $PicturesFolder "OutlookImages"
if (-not (Test-Path $savePath)) {
New-Item -ItemType Directory -Path $savePath | Out-Null
}
$images = @()
$index = 1
foreach ($att in $mail.Attachments) {
$ext = [System.IO.Path]::GetExtension($att.FileName).ToLower()
if ($ext -match "\.(jpg|jpeg|png|gif|bmp|webp)") {
$safeName = $att.FileName -replace '[\\/:*?"<>|]', '_'
$imagePath = Join-Path $savePath ("{0:D3}_{1}" -f $index, $safeName)
$att.SaveAsFile($imagePath)
$images += $imagePath
$index++
}
}
if ($images.Count -eq 0) {
Write-Error "No images found."
exit
}
$outputPdf = Join-Path $savePath "images-from-email.pdf"
#magick @images "$outputPdf"
& magick $images -auto-orient "$outputPdf"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment