From 10eecf17f5b6c2ccf9633473a65cb00c61727da5 Mon Sep 17 00:00:00 2001 From: Yorick Barbanneau Date: Wed, 11 Apr 2018 23:08:20 +0200 Subject: [PATCH] Add ErrorAction Stop for Get-ItemProperty in DelRegKey() --- cleanW10.ps1 | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/cleanW10.ps1 b/cleanW10.ps1 index 3b47be0..f56fd21 100755 --- a/cleanW10.ps1 +++ b/cleanW10.ps1 @@ -316,26 +316,25 @@ function DelRegKey { Write-Host -NoNewline "`tDelete registery key $($params.key) : " if ( ! (Test-Path $params.path) ){ Write-Host -ForegroundColor Red " Error (path not found)" - return + return } try { - Get-ItemProperty -Path $params.path -Name $params.key | Out-Null + Get-ItemProperty -Path $params.path -Name $params.key -ErrorAction Stop | Out-Null } catch { - Write-Host -ForegroundColor Yellow "key already deleted" - return + Write-Host -ForegroundColor Yellow "key not exist (already deleted?)" + return } try { - Remove-ItemProperty -Path $params.path -Name $params.key - Write-host -ForegroundColor Green "done" + Write-host -ForegroundColor Green "done" } catch [System.Security.SecurityException]{ Write-Host -ForegroundColor Red "Error (access denied)" } catch { Write-Host -ForegroundColor Red -NoNewLine "Error`n`t" - Write-Host -ForegroundColor DarkRed $Error[0].Exception.Message + Write-Host -ForegroundColor DarkRed $Error[0].Exception.Message } }