Skip to content

Commit

Permalink
add a little bit of error handling
Browse files Browse the repository at this point in the history
- add error handling for Get-WinUtilToggleStatus
  • Loading branch information
MyDrift-user committed Nov 13, 2024
1 parent 34b8c7c commit 2359a1d
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions functions/private/Get-WinUtilToggleStatus.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,34 @@ Function Get-WinUtilToggleStatus {

$ToggleSwitchReg = $sync.configs.tweaks.$ToggleSwitch.registry

if (($ToggleSwitchReg.path -imatch "hku") -and !(Get-PSDrive -Name HKU -ErrorAction SilentlyContinue)) {
$null = (New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS)
if (Get-PSDrive -Name HKU -ErrorAction SilentlyContinue) {
Write-Debug "HKU drive created successfully"
} else {
Write-Debug "Failed to create HKU drive"
try {
if (($ToggleSwitchReg.path -imatch "hku") -and !(Get-PSDrive -Name HKU -ErrorAction SilentlyContinue)) {
$null = (New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS)
if (Get-PSDrive -Name HKU -ErrorAction SilentlyContinue) {
Write-Debug "HKU drive created successfully"
} else {
Write-Debug "Failed to create HKU drive"
}
}
} catch {
Write-Error "An error occurred regarding the HKU Drive: $_"
return $false
}

if ($ToggleSwitchReg) {
$count = 0

foreach ($regentry in $ToggleSwitchReg) {
$regstate = (Get-ItemProperty -path $regentry.Path).$($regentry.Name)
if ($regstate -eq $regentry.Value) {
$count += 1
Write-Debug "$($regentry.Name) is true (state: $regstate, value: $($regentry.Value), original: $($regentry.OriginalValue))"
} else {
Write-Debug "$($regentry.Name) is false (state: $regstate, value: $($regentry.Value), original: $($regentry.OriginalValue))"
try {
$regstate = (Get-ItemProperty -path $regentry.Path).$($regentry.Name)
if ($regstate -eq $regentry.Value) {
$count += 1
Write-Debug "$($regentry.Name) is true (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): $_"
}
}

Expand Down

0 comments on commit 2359a1d

Please sign in to comment.