Today we try to list all installed programs on each VM with following script to query WMI.
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!!!"
}
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
At last, we need to merge all items both in
HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall
HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall
Code:
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
Here post explains that
The Win32_InstalledSoftwareElement and Win32_Product will only give you information about software that is installed by Microsoft Installer.
ref: WMI "installed" query different from add/remove programs list?