PowerShell 命令版本

3
Get-Command返回版本信息,但实际上这不是命令的版本,而是父模块的版本。我能定义一个与父模块不同版本的函数吗? 根据Microsoft文档,没有将version定义为基于注释的关键字。
示例:
PS C:\> Get-Command Get-ADUser

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Cmdlet          Get-ADUser                                         1.0.0.0    ActiveDirectory


PS C:\> Get-Command Get-ChildItem

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Cmdlet          Get-ChildItem                                      3.1.0.0    Microsoft.PowerShell.Management


PS C:\> Get-Module Microsoft.PowerShell.Management

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Content...}


PS C:> Get-Command -Module Microsoft.PowerShell.Management | Group-Object Version

Count Name                      Group
----- ----                      -----
   89 3.1.0.0                   {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Content...}

3
函数没有版本,命令是有版本的。它们的版本只由它们所属的父模块决定。而且这仅适用于非动态模块。如果你真的想要这个功能,你需要定义一个新的模块,仅包含该函数,并加载该模块以覆盖其他模块的定义……但为了一个函数这样做似乎需要付出很大的努力。 - Jeroen Mostert
可能只需要使用.Notes来处理这样的事情。取决于你的受众。 - Matt
1个回答

0
我可以定义一个与父模块不同版本的函数吗?
不行。

编辑:
正如Jeroen Mostert所说,您必须创建自己的模块并定义其版本。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接