So I am trying to find installed software using the uninstall registry keys but want to only display software by certain publishers. In my array of publishers to look for I want to use wild cards. I can get this to work with only one publisher but if I have multiple publishers it returns nothing. I have tried everything I could think of and I search for on this site and others but I am not sure why it won't work.
I have tried it with and without the last for each statement with the same results. I feel like this should be a simple fix. Here is the code:
$HKLM = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*"
$HKLM_Wow = "HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*"
$HKCU = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*"
$InstalledSoftware = Get-ChildItem $HKLM, $HKLM_Wow, $HKCU
$allSoftware = [System.Collections.ArrayList]@()
$SoftwarePub = [System.Collections.ArrayList]@("Microsoft*", "Dell*")
foreach($obj in $InstalledSoftware) {
$software = New-Object -TypeName PSObject
$software | Add-Member -MemberType NoteProperty -Name DisplayName -Value $obj.GetValue("DisplayName")
$software | Add-Member -MemberType NoteProperty -Name Version -Value $obj.GetValue("DisplayVersion")
$software | Add-Member -MemberType NoteProperty -Name Publisher -Value $obj.GetValue("Publisher")
$software | Add-Member -MemberType NoteProperty -Name InstallDate -Value $obj.GetValue("InstallDate")
$null = $allSoftware.Add($software)
}
foreach ($pub in $SoftwarePub)
{
$allSoftware | Where-Object {$_.Publisher -like $SoftwarePub}
}