Publisher to PDF script erro

Melissa 25 Reputation points
2026-09-22T14:16:11.9766667+00:00

How do I fix this error when trying to convert all Publisher files to pdf?

.\Convert-PubFileToPDF.ps1 : The term '.\Convert-PubFileToPDF.ps1' is not recognized as the name of a cmdlet,

function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the

path is correct and try again.

At line:1 char:1

  • .\Convert-PubFileToPDF.ps1 -Filter "C:\PublisherFiles*.pub" -Recurse
  • 
        + CategoryInfo          : ObjectNotFound: (.\Convert-PubFileToPDF.ps1:String) [], CommandNotFoundException
    
        + FullyQualifiedErrorId : CommandNotFoundException
    
Microsoft 365 and Office | Publisher | Other
0 comments No comments

Answer accepted by question author
Marcin Policht 109.8K Reputation points MVP Volunteer Moderator
2026-09-22T14:45:05.74+00:00

That error is occurring before the script runs. PowerShell cannot find Convert-PubFileToPDF.ps1 in your current directory.

First, check where PowerShell is currently looking:

Get-Location

Then check whether the script is actually in that folder:

Test-Path .\Convert-PubFileToPDF.ps1

If that returns False, change to the folder containing the script. For example, if you saved it in C:\Scripts:

Set-Location C:\Scripts

Then verify:

Test-Path .\Convert-PubFileToPDF.ps1

It should return True. You can then run:

.\Convert-PubFileToPDF.ps1 -Filter "C:\PublisherFiles*.pub" -Recurse

Alternatively, specify the complete path to the script without changing directories:

C:\Scripts\Convert-PubFileToPDF.ps1 -Filter "C:\PublisherFiles*.pub" -Recurse

If the script is downloaded from the Internet and Windows has blocked it, you may also need:

Unblock-File C:\Scripts\Convert-PubFileToPDF.ps1

Then run it again.

One other possibility is that the file was saved with a different extension, such as Convert-PubFileToPDF.ps1.txt. Check with:

Get-ChildItem C:\Scripts\Convert-PubFileToPDF*

If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

hth

Marcin

Was this answer helpful?

2 people found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. Senthil kumar 2,580 Reputation points
    2026-09-22T14:51:35.9633333+00:00

    Hi @Melissa

    Can you please try with powershell. in the same command prompt type 'powershell' it will changed to powershell command prompt. from there you can try it will work.

    Thanks.

    Was this answer helpful?


  2. AI answer

    2026-09-22T14:16:24.6633333+00:00

    CommandNotFoundException means PowerShell cannot find .Convert-PubFileToPDF.ps1 at the path being used.

    Try this:

    1. Verify the script file actually exists in the current folder.
      • .Convert-PubFileToPDF.ps1 only works when the script is in the current working directory.
      • Check the current directory path with:
             Convert-Path .
        
    2. If the script is in a different folder, run it by full path instead of .Convert-PubFileToPDF.ps1.
      • Example pattern:
             C:\Path\To\Convert-PubFileToPDF.ps1 -Filter "C:\PublisherFiles\*.pub" -Recurse
        
    3. If the path contains characters that should be treated literally, use the exact script path.
      • PowerShell cmdlets such as Publish-Script distinguish between -Path and -LiteralPath; -LiteralPath does not support wildcards. This is useful when working with exact paths.
    4. Confirm the script name is spelled exactly right, including the .ps1 extension.
    5. If the script was downloaded for bulk conversion, make sure it was downloaded to the machine before running it. The bulk conversion guidance requires downloading the sample script, then running it against the files or directories needed.

    For the Publisher bulk conversion scenario, the documented usage pattern is:

    Convert-PubFileToPDF.ps1 -Filter "C:\Documents\*.pub" -Recurse
    

    That command assumes the script file is already present in the location from which PowerShell is being run.


    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.