Skip to content

Instantly share code, notes, and snippets.

@szymonk92
Created April 27, 2018 07:01
Show Gist options
  • Save szymonk92/d69dc0947bd2dfcb6e93296b4e4689b6 to your computer and use it in GitHub Desktop.
Save szymonk92/d69dc0947bd2dfcb6e93296b4e4689b6 to your computer and use it in GitHub Desktop.
$documents_path = '.'
$word_app = New-Object -ComObject Word.Application
# This filter will find .doc as well as .docx documents
Get-ChildItem -Path $documents_path -Filter *.doc? | ForEach-Object {
$document = $word_app.Documents.Open($_.FullName)
$pdf_filename = "$($_.DirectoryName)\$($_.BaseName).pdf"
$document.SaveAs([ref] $pdf_filename, [ref] 17)
$document.Close()
}
$word_app.Quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment