diff --git a/cleanW10.ps1 b/cleanW10.ps1 index 39b74a5..9f1c8a4 100755 --- a/cleanW10.ps1 +++ b/cleanW10.ps1 @@ -220,10 +220,10 @@ function AddRegKey { [Parameter(Mandatory=$true)] [object]$params ) - if ( -not $params.ContainsKey('path') -or -not $params.ContainsKey('key') ) { - Write-Host -ForegroundColor Red -NoNewline "Error in AddRegKey : no path, key or value`n" - return - } + if ( -not $params.ContainsKey('path') -or -not $params.ContainsKey('key') ) { + Write-Host -ForegroundColor Red -NoNewline "Error in AddRegKey : no path, key or value`n" + return + } if ( -not $params.ContainsKey('value') ) { $params.value = "" } @@ -251,28 +251,28 @@ function AddRegKey { } #Let's begin... - Write-Host -NoNewline "`t$($params.path.substring(0,30))...$($params.key) reg key to $($params.value) : " - if ( -not (Test-Path $params.path) ){ - Write-Host -NoNewline -ForegroundColor DarkGreen "creating path " - try { - New-Item -Path $params.path -Force | Out-Null - } - - catch { - Write-Host -NoNewLine -ForegroundColor Red "Error`n`t" - Write-Host -ForegroundColor DarkRed $Error[0].Exception.Message - return - } + Write-Host -NoNewline "`t$($params.path.substring(0,30))...$($params.key) reg key to '$($params.value)' : " + if ( -not (Test-Path $params.path) ){ + Write-Host -NoNewline -ForegroundColor DarkGreen "creating path " + try { + New-Item -Path $params.path -Force | Out-Null } + catch { + Write-Host -NoNewLine -ForegroundColor Red "Error`n`t" + Write-Host -ForegroundColor DarkRed $Error[0].Exception.Message + return + } + } # Test if the key already exist try { $current_value = Get-ItemPropertyValue -Path $params.path -Name $params.key - if ( $current_value -eq $params.value ) { - Write-Host -ForegroundColor Yellow "Already done" - return - } - else { Write-Host -NoNewline -ForegroundColor DarkGreen "old value $current_value " } + if ( -not $current_value ) { $current_value = "" } + if ( $current_value -eq $params.value ) { + Write-Host -ForegroundColor Yellow "Already done" + return + } + else { Write-Host -NoNewline -ForegroundColor DarkGreen " old value $current_value - " } } catch { Write-Host -NoNewline -ForegroundColor DarkGreen "new key " @@ -281,7 +281,7 @@ function AddRegKey { # Put the key try { Set-ItemProperty -Path $params.path -Name $params.key -Value $params.value -Type $params.type -Force - Write-Host -ForegroundColor Green "done" + Write-Host -ForegroundColor Green "done" } catch [System.Security.SecurityException]{ Write-Host -ForegroundColor Red "Error (access denied)"