Scenario: You want to quickly search multiple remote servers to see if a specific program is installed.
Script: The following script checks to see if Wireshark is installed on any of our Exchange servers.
#Declare Server Variable $Ex2013 = Get-exchangeserver ex* | Select -expandproperty Name #Perform the Query against each server $Ex2013 | %{"Checking WireShark on $_";Invoke-Command -Computer $_ -ScriptBlock { #Declare App $appToMatch = '*Wireshark*' #Determine Uninstall Directory if ([IntPtr]::Size -eq 4) { $regpath = 'HKLM:SoftwareMicrosoftWindowsCurrentVersionUninstall*' } else { $regpath = @( 'HKLM:SoftwareMicrosoftWindowsCurrentVersionUninstall*' 'HKLM:SoftwareWow6432NodeMicrosoftWindowsCurrentVersionUninstall*' ) } #Get all Programs Installed $1 = Get-ItemProperty $regpath | .{process{if($_.DisplayName -and $_.UninstallString) { $_ } }} | Select DisplayName, Publisher, InstallDate, DisplayVersion, UninstallString |Sort DisplayName #Filter based on program $result = $1 | where {$_.DisplayName -like $appToMatch} #Display the result if found If($result -ne $null){ Write-Host " The following matching $appToMatch are Installed on $($env:computername) " -ForegroundColor Yellow Write-Host "$($result.displayName) " -ForegroundColor Yellow } }}