From e2fe868454f84c78b67cc26aa04c328854f31d91 Mon Sep 17 00:00:00 2001 From: Yorick Barbanneau Date: Mon, 16 Apr 2018 16:29:55 +0200 Subject: [PATCH] Test if registry key value is null of empty in AddRegKey() --- cleanW10.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cleanW10.ps1 b/cleanW10.ps1 index 9f1c8a4..c5234a7 100755 --- a/cleanW10.ps1 +++ b/cleanW10.ps1 @@ -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 }