Get-Command
返回版本信息,但这实际上不是命令的版本,而是来自父模块的版本。 我可以定义一个与父模块版本不同的函数吗?
根据 Microsoft docs ,没有版本定义为基于评论的帮助关键字。
例子:
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...}
最佳答案
Can I define a function with a different version than parent module?
没有。
编辑:
正如 Jeroen Mostert 所说,您必须创建自己的模块并定义其版本。
关于PowerShell 命令版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45800435/