今天我们尝试使用以下脚本列出每个VM上所有已安装的程序,以查询WMI。
我们发现它将列出所有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
答案 0 :(得分:4)
最后,我们需要合并
中的所有项目HKLM:\ SOFTWARE \微软\的Windows \ CurrentVersion \卸载
HKLM:\ SOFTWARE \ Wow6432Node \微软\的Windows \ CurrentVersion \卸载
代码:
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解释了
Win32_InstalledSoftwareElement和Win32_Product只会提供 您有关Microsoft安装的软件的信息 安装程序。
参考:WMI "installed" query different from add/remove programs list?