我想用Powershell脚本在我的电脑上安装一个软件。
在安装之前,我想检查我的安装文件版本是否比安装的程序更新。
对于已安装的程序,我可以获得DisplayName, Version等…
但我需要得到安装文件的DisplayName之前,用这个DisplayName进行一些查询。
例如
我已经安装了npp.7.9.5.Installer。x64 (Version 7.9.5)和
我想安装npp.8.1.7.Installer。x64 (Version 8.1.7)
我可以用这个获取版本和名称,(对于我电脑中安装的程序)
Get-WmiObject -Class Win32_Product | select Name, Version
但是我想知道我是否可以从我的npp.8.1.7.Installer.x64.exe获得相同的信息文件,(类似于从安装程序中提取信息)
notepad++的开发人员似乎做得很好。他们将正确的版本号放到安装文件中。因此,您可以通过获取安装程序文件的属性来轻松获取PowerShell的信息,如下所示:
$NPPInstallerFile = Get-Item -Path 'D:olafDownloadsnpp.8.1.7.Installer.x64.exe'
$NPPInstallerFile.VersionInfo.FileVersion
$NPPInstallerFile.VersionInfo.ProductVersion
提供如下输出:
8.1.7.0
8.17
除了奥拉夫的答案,你还可以做
$NPPInstallerFile = Get-Item -Path 'D:Downloadsnpp.8.1.7.Installer.x64.exe'
$NPPInstallerFile.VersionInfo | Format-List *
查看版本的所有信息,如:
FileVersionRaw : 8.1.7.0
ProductVersionRaw : 8.1.7.0
Comments :
CompanyName : Don HO don.h@free.fr
FileBuildPart : 7
FileDescription : Notepad++ : a free (GNU) source code editor
FileMajorPart : 8
FileMinorPart : 1
FileName : D:Downloadsnpp.8.1.7.Installer.x64.exe
FilePrivatePart : 0
FileVersion : 8.1.7.0
InternalName :
IsDebug : False
IsPatched : False
IsPrivateBuild : False
IsPreRelease : False
IsSpecialBuild : False
Language : Engels (Verenigde Staten)
LegalCopyright : Copyleft 1998-2017 by Don HO
LegalTrademarks :
OriginalFilename :
PrivateBuild :
ProductBuildPart : 7
ProductMajorPart : 8
ProductMinorPart : 1
ProductName : Notepad++
ProductPrivatePart : 0
ProductVersion : 8.17
SpecialBuild :
没有DisplayName
属性。也许你想要FileDescription
或ProductName
?