Author Posts

August 11, 2014 at 9:18 am

Get-wmiobject Win32Reg_AddRemovePrograms -computername (get-content c:\users\kefarrell\PROSERVERLIST.txt) | Where {$_.DisplayName -like '*Silverlight*' -or $_.DisplayName -like '*7-Zip*' -or $_.DisplayName -like '*PowerISO*' -or $_.DisplayName -like '*Flash*' -or $_.DisplayName -like '*CCleaner*' -or $_.DisplayName -like '*virtualclone drive*' -or $_.DisplayName -like '*unlocker*' -or $_.DisplayName -like '*Recuva*' -or $_.DisplayName -like '*Revo*'} | select-object pscomputername,DisplayName | Export-CSV 'c:\users\kefarrell\server-addin-queryresults.csv'

August 11, 2014 at 10:25 am

For simplicity in reading, I would move away from the one-liner (although this could all be smashed into a single line). Try looping through the computers like this:

$results = @()
$included = @('Silverlight','7-Zip','PowerISO','Flash','CCleaner','virtualclone drive','unlocker','Recuva','Revo')

$results = foreach($computer in (get-content c:\users\kefarrell\PROSERVERLIST.txt)) {
    Get-wmiobject Win32Reg_AddRemovePrograms -computername $computer |
    Where {$displayName = $_.DisplayName; @($included | Where{$displayName -like "*$_*"})} |
    Select-Object @{Label='ComputerName';Expression={$Computer}},DisplayName
}

$results | Export-CSV 'c:\users\kefarrell\server-addin-queryresults.csv'

Typically, if you are connecting to remote computers you want to use Test-Connection to verify it's online before attempting WMI because the timeout adds a lot of time to the script running.