PowerShell:使用PowerShell检查Firefox版本

PowerShell:使用PowerShell检查Firefox版本,powershell,batch-file,firefox,Powershell,Batch File,Firefox,正在尝试使用powershell bat脚本卸载firefox。但是我需要知道当前运行的是哪个Firefox版本,以及program files/下的文件夹名是什么!我写了很多长篇剧本,比如: 但我只想要一些简单的东西,只返回当前的firefox版本 假设Firefox安装在典型位置: wmic datafile where name='c:\\program files (x86)\\Mozilla Firefox\\Firefox.exe' get version 只需在PowerShel

正在尝试使用powershell bat脚本卸载firefox。但是我需要知道当前运行的是哪个Firefox版本,以及program files/下的文件夹名是什么!我写了很多长篇剧本,比如:


但我只想要一些简单的东西,只返回当前的firefox版本

假设Firefox安装在典型位置:

wmic datafile where name='c:\\program files (x86)\\Mozilla Firefox\\Firefox.exe' get version

只需在PowerShell中尝试下面的命令-

PS> gp HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |Select DisplayName, DisplayVersion, Publisher, InstallDate, HelpLink, UninstallString |ogv

这将显示一个弹出窗口,其中包含已安装软件的所有版本详细信息。在其中添加条件并将DisplayName设置为Firefox

您将获得该版本

在x64机器上,如果要使用gp执行此操作,则需要

PS> gp HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select DisplayName, DisplayVersion, Publisher, InstallDate, HelpLink, UninstallString |ogv
谢谢

,以及有关如何在Windows上使用它的说明。这一行程序将获得您当前的Firefox版本(假定您位于正确的文件夹中或Firefox位于系统路径中):


由于有一个记录在案的bug,
|写入输出
位目前至关重要。然后将结果转换为字符串(也是必需的)并保存为变量。

Get-WmiObject-Class Win32\u Product将是检查安装内容的命令。不要使用Get-WmiObject-Class Win32\u Product。它触发系统上安装的每个软件包的重新配置。请不要只发布代码作为答案,还要解释代码的作用以及它是如何解决问题的。带有解释的答案通常更有帮助,质量更好,更容易吸引选票
$firefox = (Get-Item (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\firefox.exe').'(Default)').VersionInfo
$firefox = (Get-Item (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\firefox.exe').'(Default)').VersionInfo