Ich habe ein Powershell-Skript (setup.ps1
), die wir als Einstiegspunkt für die Setup-Skripte unserer Entwicklungsumgebung verwenden. Es braucht einen Parameter:
param(
[Parameter(Position=0,HelpMessage="The targets to run.")]
[Alias("t")]
[string[]]
$Targets = "Help"
)
Wenn ich renne
PS > get-help .\setup.ps1 -detailed
im Parameterbereich wird meine Hilfemeldung nicht angezeigt:
PARAMETERS
-Targets <String[]>
Was muss ich tun, damit die Hilfemeldungen für meine Parameter angezeigt werden?
Sie setzen einen bestimmten Kommentarstil oben in die Datei, der vom PowerShell-Hilfesystem dekodiert werden kann. Hier ist ein Beispiel:
<#
.SYNOPSIS
.
.DESCRIPTION
.
.PARAMETER Path
The path to the .
.PARAMETER LiteralPath
Specifies a path to one or more locations. Unlike Path, the value of
LiteralPath is used exactly as it is typed. No characters are interpreted
as wildcards. If the path includes escape characters, enclose it in single
quotation marks. Single quotation marks tell Windows PowerShell not to
interpret any characters as escape sequences.
.EXAMPLE
C:\PS>
<Description of example>
.NOTES
Author: Keith Hill
Date: June 28, 2010
#>
function AdvFuncToProcessPaths
{
[CmdletBinding(DefaultParameterSetName="Path")]
param(
[Parameter(Mandatory=$true, Position=0, ParameterSetName="Path",
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Path to ...")]
[ValidateNotNullOrEmpty()]
[string[]]
$Path,
[Alias("PSPath")]
[Parameter(Mandatory=$true, Position=0, ParameterSetName="LiteralPath",
ValueFromPipelineByPropertyName=$true,
HelpMessage="Path to ...")]
[ValidateNotNullOrEmpty()]
[string[]]
$LiteralPath
)
...
Weitere Informationen finden Sie im Hilfethema - man about_comment_based_help
.
Wenn Sie einen Hilfeheader definiert haben, können Sie einfach eine Anmerkung (#) hinter dem Parameter verwenden (in diesem Beispiel: # Die auszuführenden Ziele. ):
<#
.SYNOPSIS
.
.DESCRIPTION
.
.PARAMETER Path
The path to the .
.PARAMETER LiteralPath
Specifies a path to one or more locations. Unlike Path, the value of
LiteralPath is used exactly as it is typed. No characters are interpreted
as wildcards. If the path includes escape characters, enclose it in single
quotation marks. Single quotation marks tell Windows PowerShell not to
interpret any characters as escape sequences.
#>
Param(
[String]$Targets = "Help" #The targets to run.
)
Ergebnisse in:
PS C:\> Get-help .\Setup.ps1 -Detailed
NAME
C:\Setup.ps1
SYNOPSIS
.
SYNTAX
C:\Setup.ps1 [[-Targets] <String>] [<CommonParameters>]
DESCRIPTION
.
PARAMETERS
-Targets <String>
The targets to run.
eins braucht nur das <# .SYNOPSIS #>
Teil oben der Datei, damit sie funktioniert, und Sie können Ihre Parameter inline auskommentieren:
<# .SYNOPSIS #>
param(
[String]$foo ## my 1st cool param
,[Switch]$bar ## my 2nd crazy switch
)
...
(überprüft mit PS 5.1.14409.1018
)