Save Get-Help PureStoragePowerShell to PDF

I met with a customer this past week and they asked if we had a copy of all of our PowerShell help in Portable Document Format (PDF). Unfortunately at that moment we did not but now we do thanks to a little PowerShell and Microsoft Word.

The first step in the script is to setup a variable to define the output file of the contents from Get-Help.

Next is to run the Get-Command for the PureStoragePowerShell module then iterate through that output to get full details for each cmdlet and pass the content to the previously defined output file.

Now begins creating the PDF file. First set a variable to use for the PDF output file name.

We can open up the output file from the beginning in Word and just use Word’s feature to save a PDF file. An important detail is that the system this will be run on requires that Microsoft Word be installed.

When creating the new Word COM object we set it to be invisible, just change that to $true and it will show Word while the script runs. All that is happening here is that the output file is being opened in Microsoft Word.

The basic output from the Get-Help command does not have any specific title information so with the next few lines of script we create a basic title to be added to the document before it is saved as a PDF.

Finally we save the file and clean-up close the document (pdf) and quitting Word. There was a variable set earlier in the script $wdExportFormatPDF = 17 which defines that PDF is the format.

One thing to be careful of when testing this script is that if a new Word COM object is created and the $word.Quit() is never run there will be Microsoft Word processes running on the system just not visible. You can check this using CTRL+SHIFT+ESC to access the Task Manager.

Below is the entire script:

Thanks Chris N. for the great idea!