C KIRAN
C KIRAN

Reputation: 1

I need a script for SCCM detection key to Match Value Data

/* I need a script SCCM detection key for match "Value Data" in "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" Without using "ValueName" Match "ValueData".*/

How to resolve this issue?

$properties = Get-ItemProperty -Path $_.PSPath

Upvotes: 0

Views: 48

Answers (1)

Mathias R. Jessen
Mathias R. Jessen

Reputation: 174825

Enumerate all the keys using Get-ChildItem, then use the synthetic Property property on each key to discover the attached property names, then finally test the value of each until you find a matching one:

# define search term and parent key
$searchTerm = 'ValueDataGoesHere'
$parentKey = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'

# locate all matching keys
$matchingKeys = @(
  # enumerate subkeys under parent
  Get-ChildItem -LiteralPath $parentKey |Where-Object {
    $key = $_
    # test each value for the search term until at least 1 is found
    $key.Property.Where({
      ($key |Get-ItemPropertyValue -Name $_) -eq $searchTerm
    }, 'First').Count -gt 0
  }
)

$matchingKeys will contain an array with any and all subkey that had a value entry containing the exact search term

If you want substring search (or want to implement a more complicated condition for the value), simply edit the comparison operation in the .Where({...}) call:

($key |Get-ItemPropertyValue -Name $_) -match ([regex]::Escape($searchTerm))

Upvotes: 0

Related Questions