PowerShell: Convert Word documents to PDF documents (Bulk)

I often have to convert Microsoft word documents to pdf. What if you have really many documents to convert, let’s say 1000 or more? Would you open each documents seperately and click on save? Bad idea. In this blog post I will give you a PowerShell function at hand which enables you to convert multiple documents with a single command. This procedure is called automation ;-). Let’s dive in.

The Objective

As already mentioned we want to convert multiple Microsoft Word documents to pdf. My cmdlet ConvertWordTo-PDF does exactly that.

Cool. By the way, you can also omit the destination parameter. Pdf files will then be saved in the source folder.


Klick on this link to download the PowerShell module.

The Code

function ConvertWordTo-PDF {


ConvertTo-PDF converts Microsoft Word documents to PDF files. 

The cmdlet queries the given source folder including sub-folders to find *.docx and *.doc files, 
converts all found files and saves them as pdf in the Destination folder. After completition, the Destination
folder with the newly created PDF files will be opened with Windows Explorer.
.PARAMETER SourceFolder
Mandatory. Enter the source folder of your Microsoft Word documents.
.PARAMETER DestinationFolder

Optional. Enter the Destination folder to save the created PDF documents. If you omit this parameter, pdf files will
be saved in the Source Folder.


ConvertWordTo-PDF -SourceFolder C:\Temp -DestinationFolder C:\Temp1
ConvertWordTo-PDF -SourceFolder C:\temp
Author: Patrick Gruenauer | Microsoft PowerShell MVP [2018-2021] 
Web: https://sid-500.com 


[Parameter (Mandatory=$true,Position=0)]
[Parameter (Position=1)]
$DestinationFolder = $SourceFolder


    $i = 0

    $word = New-Object -ComObject word.application 
    $FormatPDF = 17
    $word.visible = $false 
    $types = '*.docx','*.doc'

    If ((Test-Path $SourceFolder) -eq $false) {
    throw "Error. Source Folder $SourceFolder not found." } 

    If ((Test-Path $DestinationFolder) -eq $false) {
    throw "Error. Destination Folder $DestinationFolder not found." } 
    $files = Get-ChildItem -Path $SourceFolder -Include $Types -Recurse -ErrorAction Stop
    Write-Warning "Converting Files to PDF ..."
    foreach ($f in $files) {

        $path = $DestinationFolder + '\' + $f.Name.Substring(0,($f.Name.LastIndexOf('.')))
        $doc = $word.documents.open($f.FullName) 
        Write-Output "$($f.Name)"

    Write-Output "$i file(s) converted."
    Start-Sleep -Seconds 2 
    Invoke-Item $DestinationFolder

How to implement ConvertWordTo-PDF

Copy the code above into PowerShell ISE (ise.exe) or an editor of your choosing and run the code. Then type the command and have fun with it.

If you want to make the function permanently available, so that the function is available every time you start PowerShell, you have to create a folder in C:\Program Files\WindowsPowerShell\Modules. Name the folder ConvertWordTo-PDF. Then copy the psm1 file in that folder.


Credit goes to the author of the link below that inspired me and brought up the idea in me to create that function.


See also

Categories: PowerShell

Tagged as: ,

19 replies »

  1. Great Script, quick and easy. Just missing the “.pdf” at the End.

    You have to change line 72 from
    $path = $DestinationFolder + ‘\’ + $f.Name.Substring(0,($f.Name.LastIndexOf(‘.’)))
    $path = $DestinationFolder + ‘\’ + $f.Name.Substring(0,($f.Name.LastIndexOf(‘.’)))+”.pdf”

    then you also have the file type “.pdf” added on saveas.



  2. Insert

    $SourceFolder = (Get-Item $SourceFolder).FullName
    $DestinationFolder = (Get-Item $DestinationFolder).FullName

    between der param() and $i = 0

    That makes relative pathes posible:
    ConvertWordTo-PDF .\word .\pdf

    If anyone try this for pdf (it works!) – .visible = $false doesn’t work!

    Good job and thank you.

    Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.