# encoding: ascii
# api: powershell
# title: RegQuery
# description: Parses output of registry utility REG QUERY for the pattern on the specified computer. Useful for finding installed S/W since the WMI provider for installed software is not always reliable.
# version: 0.1
# type: script
# license: CC0
# x-poshcode-id: 732
# x-archived: 2009-03-12T06:26:34
#
#
# ---------------------------------------------------------------------------
### <Script>
### <Author>
### Chad Miller
### </Author>
### <Description>
### Searches the registry key for the specified pattern on the specified computer
### Useful in finding installed S/W
### </Description>
### <Usage>
### ./RegQuery.ps1 Server1 "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" SQL
### </Usage>
### </Script>
# ---------------------------------------------------------------------------
param ($computer,$regkey,$pattern)
$p = $($regkey -replace "HKLM","HKEY_LOCAL_MACHINE") -replace "\\","\\"
$p += "(?<pattern>.*$pattern.*)"
$matchArray = @()
REG QUERY \\$computer\$regKey | foreach { if ($_ -match $p) { $matchArray += $matches.pattern }}
if ($matchArray.length -gt 0)
{ $matchArray | foreach {new-object psobject |
add-member -pass NoteProperty computer $computer |
add-member -pass NoteProperty pattern $_}}
else {new-object psobject |
add-member -pass NoteProperty computer $computer |
add-member -pass NoteProperty pattern $null}