Have you always wanted to write a book with 100 or even 1000 or more pages? With Windows PowerShell and PowerShell Book Generator, it takes only a few seconds. The PowerShell Book Generator was created by the way on the last PSConf.eu and afterwards (I try to fill the time optimally and I hope to see you there again @psconf.eu in June 2020). Basically it is about implementing the internal PowerShell help for a topic completely in book form as PDF with table of contents.The idea came to me when I saw that there are more and more books where more and more content is simply copied from the internal help into the document. Of course the generator can also be used to document your own PowerShell modules. How does the internal PowerShell help work?
With Get-Commmand -Module <ModuleName>
the functions and CmdLets of a module can be retrieved.
PS C:\Windows\system32> get-command -Module AppvClient CommandType Name Version Source ----------- ---- ------- ------ Function Get-AppvVirtualProcess 1.0.0.0 AppvClient Function Start-AppvVirtualProcess 1.0.0.0 AppvClient Cmdlet Add-AppvClientConnectionGroup 1.0.0.0 AppvClient Cmdlet Add-AppvClientPackage 1.0.0.0 AppvClient Cmdlet Add-AppvPublishingServer 1.0.0.0 AppvClient Cmdlet Disable-Appv 1.0.0.0 AppvClient Cmdlet Disable-AppvClientConnectionGroup 1.0.0.0 AppvClient Cmdlet Enable Appv 1.0.0.0 AppvClient #....
For each commandlet the complete help can now be called up again. As return value we get an object with help information.
PS C:\Windows\system32> get-Help Get-AppvVirtualProcess NAME Get-AppvVirtualProcess OVERVIEW Displays the virtual processes running on a computer. SYNTAX Get-AppvVirtualProcess [[-Name] <String[]>] [-ComputerName <String[]>] [-FileVersionInfo] [-Modules] [<CommonParameters>] Get-AppvVirtualProcess [-ComputerName <String[]>] [-FileVersionInfo] [-Modules] -Id <Int32[]> [<CommonParameters>] Get-AppvVirtualProcess [-ComputerName <String[]>] [-FileVersionInfo] [-Modules] [<CommonParameters>]
This information is retrieved completely (with the paranmeters -Full -Examples). Partly with explanations and examples (depending on the developer) and then processed by the PowerShell Book Generator. You can easily see that this also works for your own modules if they are well documented. Before use First of all the internal PowerShell help should be up to date
The PowerShell command for this is: Update-Help
So if there is not much to see in the calls above or in the generated books, an update help should be called first.First the module has to be
imported:Import modules <PathTo>\PowerShellBooks
Afterwards the book can be generated with New-PowerShellBook <OutputPath> -Module <Modulename>.
Example:
Import modules $PSScriptRoot\PowerShellBooks $Module = 'UEV'. $OutFile = '{0}\desktop\Powershell_With_{1}.pdf' -f $env:userprofile, $Module New-PowerShellBook -OutputPdfDocument $OutFile -Module $Module
To make life a little easier for the colleagues who don't like to use the PowerShell, I have included a minimal Gui. This is started with the link PowerShellBooksGui. Then select the module and the storage location.To make life a little easier for the colleagues who don't like to use the PowerShell, I have included a minimal Gui. This is started with the link PowerShellBooksGui. Then select the module and the storage location.
Below to download the scripts with the generator. Furthermore some example books.
The generator
Update 1.2
=======
* Generate TOC with internal Links
* Executable (EXE) for the GUI (generate PDF Documents from PowerShell Modules Help). Better use the PowerShell and
...Some Examples
Created with the PowerShell Book Generator
Update 1.1: TOC with internal Links
Created with the PowerShell Book Generator
Created with the PowerShell Book Generator
Created with the PowerShell Book Generator
Created with the PowerShell Book Generator
Created with the PowerShell Book Generator
Very good!
Created with the PowerShell Book Generator
Powershell_With_DnsServer
Created with the PowerShell Book Generator
Created with the PowerShell Book Generator
Created with the PowerShell Book Generator
Comments 5
Is the source in a GitHub repo somewhere?
Hi Jeff, it is a PowerShell Module. You can get it from the PowerShell Gallery (the actual source). Furthermore I will upload a current version to GutHub within the next days.
https://github.com/AndreasNick
Thanks for the advice. I should have put that in. But I don't know if the pdf dll can do that. We'll see. Unfortunately, I won't have the chance to do it all too soon.
Thanks, this is great!! One minor suggestion: Is it possible to create the TOC with hyperlinks ? I managed it to open the pdf in Word, remove the original TOC, add an new TOC and then save it back to pdf.
as always, it's not quite as easy. I use iTextSharp. This afternoon I took a look at it and really invested a lot of time. When documents are linked with iTextSharp, links and anchors become invalid. You have to correct this later or not link to different documents at all.
To realize everything of course not very fast. I would have to reprogram many things.
Well, finally I found a simple solution. We open the same document and jump to the correct position. $null= $Chunk.SetAction((new-object iTextSharp.text.pdf.PdfAction @(".\Powershell_With_UEV.pdf", $page))
Unfortunately, there is no "back" button. I'll see if I can upload a new version soon.