return computername when can't get info using Win32Reg_AddRemovePrograms

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

  • Author
    Posts
  • #17945
    Profile photo of Kelly Farrell
    Kelly Farrell
    Participant

    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
    Profile photo of Rob Simmers
    Rob Simmers
    Participant

    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.