Categories

Creating External help

In the previous post I included a line

#  .ExternalHelp   Maml-AccessFunctions.XML 

in the Add-AccessRecord function.

I have used comment based help in the past but as James found http://blogs.technet.com/jamesone/archive/2009/07/24/powershell-on-line-help-a-change-you-should-make-for-v2-3-and-how-to-author-maml-help-files-for-powershell.aspx it does increase the length of functions and I think makes them harder to understand.

I used the InfoPath template that James supplied and saved the file as accessfunctions.xml.  A modification to the first line in the file needs to occur so that it will function as a help file.  I can see me creating a number of these files so I decided to script the change.

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
param (
    [switch]$access
)
$line1 = @'
<?xml version="1.0" encoding="UTF-8"?><?mso-infoPathSolution solutionVersion="1.0.0.12" PIVersion="1.0.0.0" href="file:///C:\Users\Jamesone\Documents\windowsPowershell\PSH-Help.xsn" name="urn:schemas-microsoft-com:office:infopath:PSH-Help:" productVersion="14.0.0" ?><?mso-application progid="InfoPath.Document" versionProgid="InfoPath.Document.2"?>
<helpItems xmlns="http://msh" schema="maml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-07-13T15:24:29" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xml:lang="en-gb">
'@


if ($access) {$filepath = "c:\scripts\modules\accessfunctions\accessfunctions.xml"}

if (!(Test-Path $filepath)){Throw "File Not found"}

$file = Get-Content -Path $filepath

$file[0] = $line1

$outpath = Join-Path -Path $(Split-Path -Path $filepath -Parent) -ChildPath $("Maml-" + (Split-Path -Path $filepath -Leaf))
Set-Content -Value $file -Path $outpath

 

The script starts by defining what the first line should be.  The help files seem to be sensitive to the format of this line so I put it into a here string to get the formatting right.  I know what the files are going to be going into this script so I decided to create a switch for each module that sets the path to the xml file produced by InfoPath.

A quick test that the file exists and then we read the content, change the first line and use Set-Content to write it back out.  I added a “maml-“ prefix to the file name so that the modified help file is separate to the InfoPath file.  This makes editing the help file easier.

The help file is used as normal

get-help add-accessrecord –full    etc

InfoPath is one of those products that I’ve never really looked at before.  It looks like it should have a number of uses and as it has an object model it should be possible to work with it in PowerShell.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>