Add ErrorAction Stop for Get-ItemProperty in DelRegKey()
This commit is contained in:
parent
37bb194595
commit
10eecf17f5
1 changed files with 6 additions and 7 deletions
13
cleanW10.ps1
13
cleanW10.ps1
|
@ -316,26 +316,25 @@ function DelRegKey {
|
||||||
Write-Host -NoNewline "`tDelete registery key $($params.key) : "
|
Write-Host -NoNewline "`tDelete registery key $($params.key) : "
|
||||||
if ( ! (Test-Path $params.path) ){
|
if ( ! (Test-Path $params.path) ){
|
||||||
Write-Host -ForegroundColor Red " Error (path not found)"
|
Write-Host -ForegroundColor Red " Error (path not found)"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Get-ItemProperty -Path $params.path -Name $params.key | Out-Null
|
Get-ItemProperty -Path $params.path -Name $params.key -ErrorAction Stop | Out-Null
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
Write-Host -ForegroundColor Yellow "key already deleted"
|
Write-Host -ForegroundColor Yellow "key not exist (already deleted?)"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|
||||||
Remove-ItemProperty -Path $params.path -Name $params.key
|
Remove-ItemProperty -Path $params.path -Name $params.key
|
||||||
Write-host -ForegroundColor Green "done"
|
Write-host -ForegroundColor Green "done"
|
||||||
}
|
}
|
||||||
catch [System.Security.SecurityException]{
|
catch [System.Security.SecurityException]{
|
||||||
Write-Host -ForegroundColor Red "Error (access denied)"
|
Write-Host -ForegroundColor Red "Error (access denied)"
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
Write-Host -ForegroundColor Red -NoNewLine "Error`n`t"
|
Write-Host -ForegroundColor Red -NoNewLine "Error`n`t"
|
||||||
Write-Host -ForegroundColor DarkRed $Error[0].Exception.Message
|
Write-Host -ForegroundColor DarkRed $Error[0].Exception.Message
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue