自定义函数列表的格式概要列表

时间:2016-04-27 08:53:37

标签: powershell

我有一个powershell脚本,其中包含几个代表任务的函数。我想格式化这些函数的列表,每个函数的名称和文档中提供的概要。

对于一个函数Foo:

Get-Help Foo | Format-Table -Property Name, Synopsis

我不知道如何使用多种功能。我在使用power语法时遇到了麻烦。我不知道如何声明函数列表,因为Foo, Bar是语法错误。我还尝试将函数的名称列为字符串并将其转换为相应的对象,但我没有这样做。

如何打印自定义功能列表的名称和概要?

1 个答案:

答案 0 :(得分:2)

正如您自己想象的那样,Get-Help(别名help)cmdlet不会公开带有多个-name参数的参数集。但是,您可以定义函数的数组,迭代它并为每个函数调用Get-Help。例如:

@('Get-Content', 'Get-ChildItem') | foreach { help $_ }  | Format-Table -Property Name, Synopsis

输出:

Name          Synopsis                                                          
----          --------                                                          
Get-Content   Gets the content of the item at the specified location.           
Get-ChildItem Gets the items and child items in one or more specified locations.