Jak wyświetlić komunikaty pomocy dla parametrów skryptu Powershell?
Mam skrypt powershell (setup.ps1
), którego używamy jako punktu wyjścia dla naszych skryptów konfiguracyjnych środowiska deweloperskiego. Przyjmuje parametr:
param(
[Parameter(Position=0,HelpMessage="The targets to run.")]
[Alias("t")]
[string[]]
$Targets = "Help"
)
When I run
PS > get-help .\setup.ps1 -detailed
W sekcji Parametry nie pojawia się mój komunikat pomocy:
PARAMETERS
-Targets <String[]>
Co muszę zrobić, aby wyświetlić komunikaty pomocy z parametrami?
45
Author: Aaron Jensen, 2011-03-08
2 answers
Umieszczasz pewien styl komentarza na górze pliku, który może być dekodowany przez system pomocy PowerShell. Oto przykład:
<#
.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
)
...
Aby uzyskać więcej informacji zobacz temat pomocy - man about_comment_based_help
.
76
Author: Keith Hill,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-03-08 20:31:12
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-03-08 20:31:12
Widocznie jeśli masz zdefiniowany nagłówek pomocy, możesz po prostu użyć uwagi ( # ) za parametrem (w tym przykładzie: #cele do uruchomienia.):
<#
.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.
)
Wyniki w:
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.
15
Author: iRon,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-05-21 15:24:34
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-05-21 15:24:34