mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2024-11-14 14:45:52 -06:00
add a little bit of error handling
- add error handling for Get-WinUtilToggleStatus
This commit is contained in:
parent
34b8c7c3e4
commit
2359a1d163
@ -16,25 +16,34 @@ Function Get-WinUtilToggleStatus {
|
|||||||
|
|
||||||
$ToggleSwitchReg = $sync.configs.tweaks.$ToggleSwitch.registry
|
$ToggleSwitchReg = $sync.configs.tweaks.$ToggleSwitch.registry
|
||||||
|
|
||||||
if (($ToggleSwitchReg.path -imatch "hku") -and !(Get-PSDrive -Name HKU -ErrorAction SilentlyContinue)) {
|
try {
|
||||||
$null = (New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS)
|
if (($ToggleSwitchReg.path -imatch "hku") -and !(Get-PSDrive -Name HKU -ErrorAction SilentlyContinue)) {
|
||||||
if (Get-PSDrive -Name HKU -ErrorAction SilentlyContinue) {
|
$null = (New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS)
|
||||||
Write-Debug "HKU drive created successfully"
|
if (Get-PSDrive -Name HKU -ErrorAction SilentlyContinue) {
|
||||||
} else {
|
Write-Debug "HKU drive created successfully"
|
||||||
Write-Debug "Failed to create HKU drive"
|
} else {
|
||||||
|
Write-Debug "Failed to create HKU drive"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
Write-Error "An error occurred regarding the HKU Drive: $_"
|
||||||
|
return $false
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($ToggleSwitchReg) {
|
if ($ToggleSwitchReg) {
|
||||||
$count = 0
|
$count = 0
|
||||||
|
|
||||||
foreach ($regentry in $ToggleSwitchReg) {
|
foreach ($regentry in $ToggleSwitchReg) {
|
||||||
$regstate = (Get-ItemProperty -path $regentry.Path).$($regentry.Name)
|
try {
|
||||||
if ($regstate -eq $regentry.Value) {
|
$regstate = (Get-ItemProperty -path $regentry.Path).$($regentry.Name)
|
||||||
$count += 1
|
if ($regstate -eq $regentry.Value) {
|
||||||
Write-Debug "$($regentry.Name) is true (state: $regstate, value: $($regentry.Value), original: $($regentry.OriginalValue))"
|
$count += 1
|
||||||
} else {
|
Write-Debug "$($regentry.Name) is true (state: $regstate, value: $($regentry.Value), original: $($regentry.OriginalValue))"
|
||||||
Write-Debug "$($regentry.Name) is false (state: $regstate, value: $($regentry.Value), original: $($regentry.OriginalValue))"
|
} else {
|
||||||
|
Write-Debug "$($regentry.Name) is false (state: $regstate, value: $($regentry.Value), original: $($regentry.OriginalValue))"
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
Write-Error "An error occurred while accessing registry entry $($regentry.Path): $_"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user