如何使用 PowerShell 查找已安装的软件?

How to find installed Software with PowerShell?

PowerShell 是否有查找已安装软件的选项?主要是软件安装在 MSI 基础上。我用下面的代码试过了,但我不确定它是否可靠,是否适用于每个软件产品。例如,32 位和 64 位?

Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | `
Select DisplayName, DisplayVersion, Publisher, InstallDate | sort {[string]$PSItem}

有没有一种可靠的方法可以找到每个已安装的软件?

您可以使用以下 PowerShell 命令找到有关已安装软件、更新和修补程序的所有信息:

try{
    $InstalledSoftware = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*
    $InstalledSoftware += Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*
} catch {
    Write-warning "Error while trying to retreive installed software from inventory: $($_.Exception.Message)"
}

如果我想找到已安装的 MSI,可以使用以下方法:

$InstalledMSIs = @()
foreach ($App in $InstalledSoftware){
    if($App.PSChildname -match "\A\{[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}\}\z"){
        $InstalledMSIs += New-Object PSObject -Property @{
            DisplayName = $App.DisplayName;
            DisplayVersion = $App.DisplayVersion;
            Publisher = $App.Publisher;
            InstallDate = $App.InstallDate;
            GUID = $App.PSChildName;    
        }
    }
}

此外,您可以使用以下命令检查 Windows Server 2008 或更高版本 OS 上安装的功能:

Get-WindowsFeature -ErrorAction Stop | Where-Object {$_.Installed} | Sort-Object DisplayName

下面的命令会给你所有安装软件的详细信息(我相信这个更可靠)。

Get-WmiObject -Class Win32_Product