return computername when can't get info using Win32Reg_AddRemovePrograms

This topic contains 1 reply, has 2 voices, and was last updated by  Rob Simmers 3 years, 1 month ago.

  • Author
  • #17945

    Kelly Farrell

    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'

  • #17955

    Rob Simmers

    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.

You must be logged in to reply to this topic.