Detection Method - powershell - registry

Dude be PSing

I am working with figuring out how to create a detection method in SCCM. I have been using the method below which works. But I need a little more into

if(test-path -path <regpath>)


{
Write-Host "installed"
}

else
{
}

I am looking to use where -Name DisplayVersion -eq "7.7.1" for the detection method. Any help is greatly appreciated.

mklement0

js2010's answer works well, even in older versions of PowerShell, but it requires duplication of the value name.

In PowerShell v5 or higher you can use the Get-ItemPropertyValue cmdlet instead, which avoids the duplication:

$key = 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\xxx'
$valueName = 'DisplayVersion' # in PS terminology: *property* name 
$valueData = '7.7.1' # in PS terminology: *property value*

if ((Get-ItemPropertyValue $key $valueName) -eq $valueData) {
  "installed"
} else {
  "NOT installed"
}

If, instead, you're looking for specific property value (registry-value data) in a given property (registry value) among all the subkeys of a given registry key path:

$key = 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
$valueName = 'DisplayVersion'
$valueData = '7.7.1'

if (Get-ChildItem $key | Where { $_.GetValue($valueName) -eq $valueData }) {
  "installed"
} else {
  "NOT installed"
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related