我正在尝试Get-Help使用PowerShell从PowerShell脚本中提取注释标题。我正在读取的文件如下所示:
<#
.SYNOPSIS
Synopsis goes here.
It could span multiple lines.
Like this.
.DESCRIPTION
A description.
It could also span multiple lines.
.PARAMETER MyParam
Purpose of MyParam
.PARAMETER MySecondParam
Purpose of MySecondParam.
Notice that this section also starts with '.PARAMETER'.
This one should not be captured.
...and many many more lines like this...
#>
# Rest of the script...
Run Code Online (Sandbox Code Playgroud)
我想得到下面的所有文字.DESCRIPTION,直到的第一个实例.PARAMETER。因此,所需的输出将是:
A description.
It could also span multiple lines.
Run Code Online (Sandbox Code Playgroud)
这是我尝试过的:
<#
.SYNOPSIS
Synopsis goes here.
It could span multiple lines.
Like this.
.DESCRIPTION
A description.
It could also span multiple lines.
.PARAMETER MyParam
Purpose of MyParam
.PARAMETER MySecondParam
Purpose of MySecondParam.
Notice that this section also starts with '.PARAMETER'.
This one should not be captured.
...and many many more lines like this...
#>
# Rest of the script...
Run Code Online (Sandbox Code Playgroud)
当我运行它时,它$description是空的。如果更改$pattern为.*,则按预期方式获取文件的全部内容;所以我的RegEx模式肯定有问题,但是我似乎无法弄清楚。
有任何想法吗?
(get-help get-date).description
The `Get-Date` cmdlet gets a DateTime object that represents the current date
or a date that you specify. It can format the date and time in several Windows
and UNIX formats. You can use `Get-Date` to generate a date or time character
string, and then send the string to other cmdlets or programs.
(get-help .\script.ps1).description
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
80 次 |
| 最近记录: |