PoshCode Archive  Artifact [546a534665]

Artifact 546a5346657b8bcc0f1dd499a6dfeb8b6eeec99b9264666222e0f00188aa0b39:

  • File RegQuery.ps1 — part of check-in [4df9018676] at 2018-06-10 14:23:15 on branch trunk — 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. (user: unknown size: 1501)

# 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}