当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 在 PowerShell 中获取文件版本

作者:精品下载站 日期:2024-12-14 17:02:26 浏览:15 分类:玩电脑

在 PowerShell 中获取文件版本


在 PowerShell 中获取文件版本的命令是 Get-Command cmdlet。此命令使用 FileVersionInfo.FileVersion 属性来获取文件的版本。

文件版本和命名在文件系统目录中非常重要。文件版本信息包含文件的版本号和原始文件名。您可以使用 PowerShell 使用 Get-CommandGet-Item cmdlet 获取文件版本。

在本文中,我们将讨论如何使用 Get-Command 和其他 PowerShell cmdlet 在 PowerShell 中获取文件版本。

让我们通过示例了解如何获取文件版本获取dll程序集文件版本

使用 Get-Command 在 PowerShell 中获取文件版本

您可以使用 PowerShell Get-Command cmdlet 获取文件的文件版本。

让我们考虑一个例子,如果我们想要获取dll程序集文件版本,请使用以下命令

(Get-Command D:\PowerShell\ShellWatcher.dll).FileVersionInfo.FileVersion

在上面的命令中,Get-Command 使用 FileVersionInfo.FileVersion 属性获取指定文件的 dll 程序集文件版本。

FileVersionInfo.FileVersion 属性获取文件版本号为“主版本号.次版本号.内部版本号.私有部件号”

上述命令在 PowerShell 中获取文件版本的输出如下

[玩转系统] 在 PowerShell 中获取文件版本

酷提示:如何在 PowerShell 中按名称查找文件!

获取 Exe 文件版本 PowerShell

您可以使用 Get-Command 在 PowerShell 中获取 exe 文件版本,如下所示

 (Get-Command D:\PowerShell\ShellIndex.exe).FileVersionInfo.FileVersion    

在上面的命令中,FileVersionInfo.FileVersion属性获取指定文件的exe文件版本如下

PS C:\> (Get-Command D:\PowerShell\ShellIndex.exe).FileVersionInfo.FileVersion                   2.0.3.0
PS C:\>   

酷提示:如何在 PowerShell 中重命名计算机!

使用 Get-Item 获取 dll 程序集文件版本

在 PowerShell 中,您可以使用 Get-Item cmdlet 获取 dll 程序集文件版本,如下所示

(Get-Item D:\PowerShell\ShellWatcher.dll).VersionInfo | format-list  

PowerShell Get-Item cmdlet 获取指定位置的项目并使用 VersionInfo 属性,它在 PowerShell 中获取文件版本,如下所示

PS C:\> (Get-Item D:\PowerShell\ShellWatcher.dll).VersionInfo | format-list                                             

FileName          : D:\PowerShell\ShellWatcher.dll
FileVersion       : 19.10.20064.310990
ProductVersion    : 19.10.20064.310990

酷提示:如何在 PowerShell 中向文件添加内容!

结论

希望上述有关如何在 PowerShell 中获取文件版本以及使用 Get-Command cmdlet 获取 dll 程序集文件版本的文章对您有所帮助。

您可以在 ShellGeek 主页上找到有关 PowerShell Active Directory 命令和 PowerShell 基础知识的更多主题。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯