Get All Installed Software Using PowerShell

The following PowerShell script will return all installed software on a Windows server.

function GetInstalledMSIVersionNumber($MSIName) {
	#Define the variable to hold the location of Currently Installed Programs
	$registry = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall","SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
	$Results = "";
	foreach($UninstallKey in $registry){
		$computername="ServerName";
		#Create an instance of the Registry Object and open the HKLM base key
		$reg=[microsoft.win32.registrykey]::OpenRemoteBaseKey('LocalMachine',$computername) 
		#Drill down into the Uninstall key using the OpenSubKey Method
		$regkey=$reg.OpenSubKey($UninstallKey) 
		#Retrieve an array of string that contain all the subkey names
		$subkeys=$regkey.GetSubKeyNames() 
		#Open each Subkey and use GetValue Method to return the required values for each
		foreach($key in $subkeys){
			$thisKey=$UninstallKey+"\\"+$key 
			$thisSubKey=$reg.OpenSubKey($thisKey) 
			if ($($thisSubKey.GetValue("DisplayName"))) {
				# header: DisplayName,DisplayVersion,Publisher,InstallDate,InstallLocation,InstanceId,UninstallString,EstimatedSize
				$Results = $Results + """" + $($thisSubKey.GetValue("DisplayName") + """" + "," + """" + $thisSubKey.GetValue("DisplayVersion") + """" + "," + """" + $thisSubKey.GetValue("Publisher") + """" + "," + """" + $thisSubKey.GetValue("InstallDate") + """" + "," + """" + $thisSubKey.GetValue("InstallLocation") + """" + "," + """" + $thisSubKey.GetValue("InstanceId") + """" + "," + """" + $thisSubKey.GetValue("UninstallString") + """" + "," + """" + $thisSubKey.GetValue("EstimatedSize") + """" + "`n");
			}
		} 
	}
	return $Results;
}
$Results = GetInstalledMSIVersionNumber("");
$Results;

Leave a Reply