如何将输入类型添加到 cmdlet 帮助主题
笔记
手动编写基于 XML 的帮助非常困难。 PlatyPS 模块允许您在 Markdown 中编写帮助,然后将其转换为基于 XML 的帮助。这使得编写和维护帮助变得更加容易。 PlatyPS 还可以为您创建可更新的帮助包。有关详细信息,请参阅使用 PlatyPS 创建基于 XML 的帮助。
本部分介绍如何将 INPUTS 部分添加到 PowerShell cmdlet 帮助主题。 INPUTS 部分列出了 cmdlet 按值或按属性名称接受作为管道输入的 .NET 对象类。
您可以添加到 INPUTS 部分的类数量没有限制。输入类型包含在 <command:inputTypes> 节点中,每个类包含在 <command:inputType> 元素中。
该架构在每个 <command:inputType> 元素中包含两个 <maml:description> 元素。但是,Get-Help cmdlet 仅显示 <command:inputType>/
从 PowerShell 3.0 开始,Get-Help cmdlet 显示 <maml:uri> 元素的内容。此元素可让您将用户引导至描述 .NET 类的主题。
以下 XML 显示 <maml:inputTypes> 节点。
<command:inputTypes>
<command:inputType>
<dev:type>
<maml:name> Class name </maml:name>
<maml:uri> URI of a topic that describes the class </maml:uri>
<maml:description/>
</dev:type>
<maml:description>
<maml:para> Brief description </maml:para>
</maml:description>
</command:inputType>
</command:inputTypes>
以下 XML 显示了使用 <maml:inputTypes> 节点记录输入类型的示例。
<command:inputTypes>
<command:inputType>
<dev:type>
<maml:name>System.DateTime</maml:name>
<maml:uri>https://learn.microsoft.com/dotnet/api/system.datetime</maml:uri>
<maml:description/>
</dev:type>
<maml:description>
<maml:para> You can pipe a date to the Set-Date cmdlet. <maml:para>
<maml:description>
</command:inputType>
</command:inputTypes>