Retrieving product installation information using WMI via Powershell on a remote machine

The WMI class Win32_product can be used to obtain a list of all the products installed on a remote machine. Below is a PowerShell example of how to use the Win32_Product class to retrieve product information from a remote machine:

Get-WmiObject -Class Win32_Product -ComputerName "remotecomputer" | Select-Object __Server , Name , Version , RegCompany , InstallLocation   | Export-Csv -NoTypeInformation "c:\\text.csv"

This Win32_product class is by default not present on the Windows 2003 machine.

In order to install the WMI Windows Installer Provider you need to take the below steps:

  • "Add/Remove Programs"
  • "Add/Remove Windows Components"
  • "Management and Monitoring Tools"
  • Check "WMI Windows Installer Provider."
  • "OK", "Next" and "Finish"

You might need the installation disk or at least the i386 folder. You need to reboot the machine after this installation.

Once this class is available, you can use the above PowerShell script to get the information.

If you do not want to install this provider, you can query the same information from the registry.

An example of how to read the product installation information on a windows 2003 machine from the registry is provided below:

$computerName = "remotecomputer"

$strLine = @();

$regPath = @('Software\Microsoft\Windows\CurrentVersion\Uninstall');

$keyName = 'LocalMachine';

$registry = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($keyName, $computer);

$regKey = $registry.OpenSubKey($regPath);

if ($regKey -ne $null)

{

$keys = $regKey.GetSubKeyNames();

      foreach ($name in $keys)

      {

         $properties = $regKey.OpenSubKey($name);

         $displayName = $properties.GetValue('DisplayName');

         if ($displayName -ne $null)

         {

         $displayVersion = $properties.GetValue('DisplayVersion');

         $publisher = $properties.GetValue('Publisher');

         $installLocation = $properties.GetValue('InstallLocation');

                         

         # create an object that will be added to the array $Responses

        $Response = New-Object PSObject

                             

         # add the members to our newly created $Response object

            Add-Member -InputObject $Response -MemberType NoteProperty -Name Name -Value $displayName

            Add-Member -InputObject $Response -MemberType NoteProperty -Name Version -Value $displayVersion

            Add-Member -InputObject $Response -MemberType NoteProperty -Name Publisher -Value $publisher

            Add-Member -InputObject $Response -MemberType NoteProperty -Name InstallLocation -Value $installLocation

                             

            # add the object to the array

            $strLine += $Response

            $properties.close();

            }

     }

      $regKey.close();

  }

  $registry.close();

  $strLine | Export-Csv -path c:\newFile.csv -NoTypeInformation    

Registry key 'Software\Microsoft\Windows\CurrentVersion\Uninstall' contains all the product details.

In the above script, we are reading computer name from $computerName variable and enumerating the registry key to get the product information. Output will be generated into the csv file "c:\NewFile.csv". The security context under which the script is running should have the WMI access to the remote machine.