Skip to content

Instantly share code, notes, and snippets.

@mikequentel
Last active April 26, 2017 18:38
Show Gist options
  • Save mikequentel/6d7fb5042f9b3397e7fadf12b532e0a3 to your computer and use it in GitHub Desktop.
Save mikequentel/6d7fb5042f9b3397e7fadf12b532e0a3 to your computer and use it in GitHub Desktop.
# https://blogs.technet.microsoft.com/heyscriptingguy/2011/11/13/use-powershell-to-quickly-find-installed-software/
# Example finding location of 7-zip
$computername=(get-childitem -path env:computername).value
$UninstallKey="SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
$reg=[microsoft.win32.registrykey]::OpenRemoteBaseKey('LocalMachine',$computername)
$regkey=$reg.OpenSubKey($UninstallKey)
$subkeys=$regkey.GetSubKeyNames()
$array = @()
foreach($key in $subkeys){
$thisKey=$UninstallKey+"\\"+$key
$thisSubKey=$reg.OpenSubKey($thisKey)
$obj = New-Object PSObject
$obj | Add-Member -MemberType NoteProperty -Name "ComputerName" -Value $computername
$obj | Add-Member -MemberType NoteProperty -Name "DisplayName" -Value $($thisSubKey.GetValue("DisplayName"))
$obj | Add-Member -MemberType NoteProperty -Name "DisplayVersion" -Value $($thisSubKey.GetValue("DisplayVersion"))
$obj | Add-Member -MemberType NoteProperty -Name "InstallLocation" -Value $($thisSubKey.GetValue("InstallLocation"))
$obj | Add-Member -MemberType NoteProperty -Name "Publisher" -Value $($thisSubKey.GetValue("Publisher"))
$array += $obj
}
# $array | Where-Object { $_.DisplayName } | select ComputerName, DisplayName, DisplayVersion, Publisher | ft -auto
# $array | Where-Object { $_.DisplayName -eq "7-Zip 16.02 (x64)"} | select DisplayName, InstallLocation| ft -auto
$array | Where-Object { $_.DisplayName -eq "7-Zip 16.02 (x64)"} | select InstallLocation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment