Heisenberg在这里:当您不记录cmdlet

时间:2015-06-07 21:14:45

标签: powershell documentation-generation maml

在尝试为我的PowerShell cmdlet(用C#编写,而不是脚本编写)的文档尽可能完整的过程中,我做了一个有趣的发现。如果我包含正确的MAML帮助文件(例如MyModule.dll-Help.xml),那么显示包含一个或多个别名的cmdlet参数的帮助可能如下所示:

PS> Get-Help Set-MySetting -param ItemType
-ItemType <ItemTypeChoice>
    The type for the item.    
    Required?                    false
    Position?                    4
    Default value                String
    Accept pipeline input?       true (ByPropertyName)
    Accept wildcard characters?  false

另一方面,如果我删除了该帮助文件并重新加载了我的模块,那么相同参数的帮助 - 现在只是通过Get-Help从代码本身反映出来 - 可能如下所示:

PS> Get-Help Set-MySetting -param ItemType
-ItemType <ItemTypeChoice>
    The type for the item.    
    Required?                    false
    Position?                    4
    Accept pipeline input?       true (ByPropertyName)
    Parameter set name           (All)
    Aliases                      Type, SettingType
    Dynamic?                     false

请注意第二个实例中存在Aliases属性,第一个实例中是否存在该属性。

当然,首先认为我的MAML必须是不正确的。考虑到通过广泛的网络搜索,我还没有像MAML XML模式(!)的权威来源那样远程地找到任何东西,这种可能性更可能发生。但是,如果我的MAML不正确,那么用于PowerShell自己的核心cmdlet的MAML也是如此,因为这是我从中复制它的地方,认为它是一个可靠的源(C:\ Windows \ System32 \ WindowsPowerShell \ v1.0 \ EN-US \ Microsoft.PowerShell.Commands.Management.dll-help.xml)。

但问题的关键证据是,即使该文件中的某些PowerShell核心cmdlet具有别名,在调用Get-Help时也不报告别名!这是一个例如:

PS> Get-Help Add-Computer -param DomainName
-DomainName <String>
    Specifies the domain to which the computers are added. This parameter is required when adding the computers to a domain.    
    Required?                    true
    Position?                    1
    Default value                
    Accept pipeline input?       false
    Accept wildcard characters?  false

以下是DomainName Add-Computer参数的MAML定义的开头 - 请注意最后定义的别名:

<command:parameter required="true" variableLength="false"
    globbing="false" pipelineInput="false" position="1" aliases="DN,Domain">

因此,Get-Help知道如何在通过反射执行工作时报告别名,但在aliases <command:parameter>属性中提供别名时,它无法报告别名

问题

真正的问题是什么?

  1. Get-Help期望别名不在其他地方 aliases的{​​{1}}属性。
  2. 在给定MAML文件时,Get-Help根本无法在MAML中查找别名。
  3. 如果(1),并且有人可以确定指定别名的正确方法,那么我自己的cmdlet就有一个简单的解决方法。如果(2)......是时候在Connect上提出问题了!

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,并且可以通过将Aliases添加到参数<maml:description>部分来解决此问题。