WMI 不返回 Windows 7 64 上的所有安装程序 [英] WMI not return all install programs on Windows 7 64

查看:21
本文介绍了WMI 不返回 Windows 7 64 上的所有安装程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天我们尝试使用以下脚本列出每个 VM 上所有已安装的程序来查询 WMI.

Today we try to list all installed programs on each VM with following script to query WMI.

我们发现它会列出所有 64 位应用程序,以及一些 32 位应用程序.
但并非所有应用程序(32 位 + 64 位)都会列出.

We find out it will list out all 64 bit applications, plus some of 32 bit applications.
But not all applications (32bit + 64bit) will list out.

param(
    [string] $ExportPath = ''
)

$InstalledProducts = get-wmiobject -class Win32_Product

if (($InstalledProducts -ne $null) -and ($InstalledProducts.Count -gt 0))
{
    $fileName = ($env:COMPUTERNAME) + "-" +  (Get-Date -f "yyyy-mm-dd-hhmmss") +  ".csv"
    $fileExport = $fileName
    if(Test-Path $ExportPath) {
        $fileExport = Join-Path (Resolve-Path $ExportPath) $fileName
    }
    $InstalledProducts | 
        Select-Object @{Name="HostName"; Expression={"$env:COMPUTERNAME"}}, Name, Version, Vendor | 
        Export-CSV -Path $fileExport -Encoding UTF8
}
else
{
    Write-Host "!!!ERROR!!!"
}

我们也尝试过wmic product",它也有类似的问题.
https://superuser.com/questions/681564/how-to-list-all-applications-displayed-from-add-remove-winxp-win7-via-command-li

We also try "wmic product" it has the similar issue.
https://superuser.com/questions/681564/how-to-list-all-applications-displayed-from-add-remove-winxp-win7-via-command-li

推荐答案

最后,我们需要合并

HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall

HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall

HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall

HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall

代码:

param (
    [String] $ExportPath = '<NetworkPath>'
)

$fileName = ($ENV:COMPUTERNAME) + "-" + (Get-Date -f "yyyy-mm-dd-HHmmss") + ".csv"
$fileExport = $fileName

if (Test-Path $ExportPath) {
    $fileExport = Join-Path (Resolve-Path $ExportPath) $fileName
}

$UninstallRegList = ('HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*',
    'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*')

$UninstallRegList |
    Get-ItemProperty |
    foreach{
        if (($_.DisplayName -ne $NULL) -and ($_.DisplayName -ne "")){
            $_
        }
    } | Select-Object DisplayName, DisplayVersion, Publisher |
    Export-CSV -Path $fileExport -Encoding UTF8

这里 帖子解释说

Win32_InstalledSoftwareElement 和 Win32_Product 只会给您有关 Microsoft 安装的软件的信息安装程序.

The Win32_InstalledSoftwareElement and Win32_Product will only give you information about software that is installed by Microsoft Installer.

ref: WMI已安装"查询不同于添加/删除程序列表?

这篇关于WMI 不返回 Windows 7 64 上的所有安装程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆