如何通过 Powershell 获取所有已安装软件的完整列表?

如何通过 Powershell 获取所有已安装软件的完整列表?

我想弄清楚如何在 Windows 10 上的 Powershell 中查看所有已安装软件的版本号。我挖出了一个例子但当我将生成的列表与控制面板 > 卸载程序,它似乎不完整。例如,查询输出中缺少 Google Chrome。知道为什么吗?我对 Powershell 的经验很少,所以可能是显而易见的?

Get-WMIObject -Query "SELECT * FROM Win32_Product" |FT

Chrome 肯定已安装,但未显示在 PS 输出中: 在此处输入图片描述

答案1

尝试这个:

function Get-InstalledApps {
    param (
        [Parameter(ValueFromPipeline=$true)]
        [string[]]$ComputerName = $env:COMPUTERNAME,
        [string]$NameRegex = ''
    )
    
    foreach ($comp in $ComputerName) {
        $keys = '','\Wow6432Node'
        foreach ($key in $keys) {
            try {
                $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $comp)
                $apps = $reg.OpenSubKey("SOFTWARE$key\Microsoft\Windows\CurrentVersion\Uninstall").GetSubKeyNames()
            } catch {
                continue
            }

            foreach ($app in $apps) {
                $program = $reg.OpenSubKey("SOFTWARE$key\Microsoft\Windows\CurrentVersion\Uninstall\$app")
                $name = $program.GetValue('DisplayName')
                if ($name -and $name -match $NameRegex) {
                    [pscustomobject]@{
                        ComputerName = $comp
                        DisplayName = $name
                        DisplayVersion = $program.GetValue('DisplayVersion')
                        Publisher = $program.GetValue('Publisher')
                        InstallDate = $program.GetValue('InstallDate')
                        UninstallString = $program.GetValue('UninstallString')
                        Bits = $(if ($key -eq '\Wow6432Node') {'64'} else {'32'})
                        Path = $program.name
                    }
                }
            }
        }
    }
}

使用:Get-InstalledApps -ComputerName $env:COMPUTERNAME

相关内容