gpt4 book ai didi

windows - WMI 不返回 Windows 7 64 上的所有安装程序

转载 作者:可可西里 更新时间:2023-11-01 09:59:04 25 4
gpt4 key购买 nike

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

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

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

最佳答案

最后,我们需要合并所有项目

HKLM:\Software\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

在这里post解释说

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

引用:WMI "installed" query different from add/remove programs list?

关于windows - WMI 不返回 Windows 7 64 上的所有安装程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25882725/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com