Skip to content

Commit afeae67

Browse files
authored
Add 'Test-RegistryValue' function
1 parent 2ec4c50 commit afeae67

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

utilities/Utils.ps1

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,35 @@ function script:OnApplicationExit {
55
$script:ExitCode = 0 #Set the exit code for the Packager
66
}
77

8+
function Test-RegistryValue {
9+
<#
10+
.SYNOPSIS
11+
Check specific values within a key.
12+
13+
.DESCRIPTION
14+
Check specific values within a key, in the same way than Test-Path cmdlet for the key.
15+
16+
.EXAMPLE
17+
Test-RegistryValue -Path 'HKLM:\SOFTWARE\TestSoftware' -Value 'Version'
18+
This will return 'True' or 'False'
19+
#>
20+
param (
21+
[parameter(Mandatory=$true)]
22+
[ValidateNotNullOrEmpty()]$Path,
23+
[parameter(Mandatory=$true)]
24+
[ValidateNotNullOrEmpty()]$Value
25+
)
26+
27+
try {
28+
Get-ItemProperty -Path $Path | Select-Object -ExpandProperty $Value -ErrorAction Stop | Out-Null
29+
return $true
30+
}
31+
32+
catch {
33+
return $false
34+
}
35+
}
36+
837
function Set-RegistryKey {
938

1039
[CmdletBinding()]

0 commit comments

Comments
 (0)