PowerShell 命令版本

标签 powershell

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/

相关文章:

powershell - 可以选择从powershell将参数传递给MSBuild

azure - 来自 VSTS 管道的 PowerShell 远程

Powershell Get-ChildItem -recurse不能获取所有项目

powershell - 将以空格分隔的 PowerShell 输出解析为表格

string - 无法将 'System.Object[]'转换为 'System.String'类型

powershell - 针对 powershell 的 x64 与 x86 可变性进行编程的最佳方法是什么

json - 如何使用 PowerShell 更新 JSON 文件

azure - 获取过去 30 天内的最后一次登录,Get-MgAuditLogSignIn - PowerShell

尝试使用 "The specified network resource or device is no longer available"读取证书存储时,PowerShell 失败

Powershell - 在 json 字符串中添加变量