這實際上很可惜,這不是標準化的,因爲它會打開一種方式,從您自己的代碼中獲取信息。例如如果您想在日誌文件中記錄版本,則不希望在cmdlet的另一個命令中重新定義該版本(僅僅是因爲它可能會被遺忘並與標題不同步)。
在我的標準PowerShell LOg-Entry
framework,我使用了一些命令,使本次大會的信息容易獲得默認:
例
$My = @{File = Get-ChildItem $MyInvocation.MyCommand.Path; Contents = $MyInvocation.MyCommand.ScriptContents}
If ($My.Contents -Match '^\s*\<#([\s\S]*?)#\>') {$My.Help = $Matches[1].Trim()}
[RegEx]::Matches($My.Help, '(^|[\r\n])\s*\.(.+)\s*[\r\n]|$') | ForEach {
If ($Caption) {$My.$Caption = $My.Help.SubString($Start, $_.Index - $Start)}
$Caption = $_.Groups[2].ToString().Trim()
$Start = $_.Index + $_.Length
}
$My.Title = $My.Synopsis.Trim().Split("`r`n")[0].Trim()
$My.Notes -Split("\r\n") | ForEach {$Note = $_ -Split(":", 2); If ($Note[0].Trim()) {$My[$Note[0].Trim()] = $Note[1].Trim()}}
$My.Path = $My.File.FullName; $My.Folder = $My.File.DirectoryName; $My.Name = $My.File.BaseName
$My.Arguments = (($MyInvocation.Line + " ") -Replace ("^.*\\" + $My.File.Name.Replace(".", "\.") + "['"" ]"), "").Trim()
$My
對象:
Name Value
---- -----
DESCRIPTION <Description goes here>.
EXAMPLE Example.ps1...
Name My
Folder C:\Users\User\Scripts\Test\PowerShell
Version 1.0.0.0 20160725 Initial Build
Author Glen Buktenica
NOTES Author : Glen Buktenica...
File C:\Users\User\Scripts\Test\PowerShell\My.ps1
Title <Synopsis goes here>.
Arguments -test
SYNOPSIS <Synopsis goes here>.
Path C:\Users\User\Scripts\Test\PowerShell\My.ps1
Contents <# ...
Help .SYNOPSIS ...