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. I’m a total novice to Powershell so troubleshooting a script, even if it’s not that complicated would take me quite some time to get into. That said, I’ve got an issue concerning only files which contain a “.” inside of the file name (example: date_Dr. example.docx). It doesn’t produce an error, but the output file of file type “file”, and not pdf.
    Do you have an idea how to fix that?


  2. Many thanks for this code.
    When I run this code in windows schedule tasks, it does not work. CPU grows up to 100%.
    Any idea what can be the issue ?


  3. Hello,
    When i run the script it disappears and not working for me, i am running it on windows 10, and i just ran another script for remove duplicates by you and worked perfectly.
    please advise how to get this script working?


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 )

Twitter picture

You are commenting using your Twitter 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.