Test if registry key value is null of empty in AddRegKey()

This commit is contained in:
Yorick Barbanneau 2018-04-16 16:29:55 +02:00
parent 00e4a21767
commit e2fe868454

View file

@ -225,7 +225,7 @@ function AddRegKey {
return
}
if ( -not $params.ContainsKey('value') ) {
$params.value = ""
$params.value = $null
}
if ( -not $params.ContainsKey('type') -or $params.type -eq "" ){ $params.type="DWord" }
@ -266,9 +266,9 @@ function AddRegKey {
# Test if the key already exist
try {
$current_value = Get-ItemPropertyValue -Path $params.path -Name $params.key
if ( -not $current_value ) { $current_value = "" }
if ( $current_value -eq $params.value ) {
$current_value = (Get-ItemPropertyValue -Path $params.path -Name $params.key)
#current_value and params.value both empty need a special condition
if ( ( [string]::IsNullOrWhitespace($current_value) -and [string]::IsNullOrWhitespace($params.value) ) -or ($current_value -eq $params.value) ) {
Write-Host -ForegroundColor Yellow "Already done"
return
}