mirror of
https://github.com/ChrisTitusTech/winutil
synced 2026-06-04 14:17:27 +00:00
Cleanup Get-WinUtilToggleStatus.ps1 (#4497)
* Cleanup Get-WinUtilToggleStatus.ps1 * Update Get-WinUtilToggleStatus.ps1 * Merge branch 'main' into patch-9 * Update Get-WinUtilToggleStatus.ps1
This commit is contained in:
@@ -1,78 +1,37 @@
|
|||||||
Function Get-WinUtilToggleStatus {
|
Function Get-WinUtilToggleStatus {
|
||||||
<#
|
if (-not $ToggleSwitchReg) {
|
||||||
|
|
||||||
.SYNOPSIS
|
|
||||||
Pulls the registry keys for the given toggle switch and checks whether the toggle should be checked or unchecked
|
|
||||||
|
|
||||||
.PARAMETER ToggleSwitch
|
|
||||||
The name of the toggle to check
|
|
||||||
|
|
||||||
.OUTPUTS
|
|
||||||
Boolean to set the toggle's status to
|
|
||||||
|
|
||||||
#>
|
|
||||||
|
|
||||||
Param($ToggleSwitch)
|
|
||||||
|
|
||||||
$ToggleSwitchReg = $sync.configs.tweaks.$ToggleSwitch.registry
|
|
||||||
|
|
||||||
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
|
return $false
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($ToggleSwitchReg) {
|
New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS
|
||||||
$count = 0
|
|
||||||
|
|
||||||
foreach ($regentry in $ToggleSwitchReg) {
|
foreach ($regentry in $ToggleSwitchReg) {
|
||||||
try {
|
|
||||||
if (!(Test-Path $regentry.Path)) {
|
if (-not (Test-Path $regentry.Path)) {
|
||||||
New-Item -Path $regentry.Path -Force | Out-Null
|
New-Item -Path $regentry.Path -Force | Out-Null
|
||||||
|
}
|
||||||
|
|
||||||
|
$regstate = (Get-ItemProperty -Path $regentry.Path).$($regentry.Name)
|
||||||
|
|
||||||
|
if ($null -eq $regstate) {
|
||||||
|
switch ($regentry.DefaultState) {
|
||||||
|
"true" {
|
||||||
|
$regstate = $regentry.Value
|
||||||
}
|
}
|
||||||
$regstate = (Get-ItemProperty -path $regentry.Path).$($regentry.Name)
|
"false" {
|
||||||
if ($regstate -eq $regentry.Value) {
|
$regstate = $regentry.OriginalValue
|
||||||
$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))"
|
|
||||||
}
|
}
|
||||||
if ($null -eq $regstate) {
|
default {
|
||||||
switch ($regentry.DefaultState) {
|
Write-Error "Entry $($regentry.Name): missing value and no DefaultState"
|
||||||
"true" {
|
$regstate = $regentry.OriginalValue
|
||||||
$regstate = $regentry.Value
|
|
||||||
$count += 1
|
|
||||||
}
|
|
||||||
"false" {
|
|
||||||
$regstate = $regentry.OriginalValue
|
|
||||||
}
|
|
||||||
default {
|
|
||||||
Write-Error "Entry for $($regentry.Name) does not exist and no DefaultState is defined."
|
|
||||||
$regstate = $regentry.OriginalValue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch {
|
|
||||||
Write-Error "An unexpected error occurred: $_"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($count -eq $ToggleSwitchReg.Count) {
|
if ($regstate -ne $regentry.Value) {
|
||||||
Write-Debug "$($ToggleSwitchReg.Name) is true (count: $count)"
|
|
||||||
return $true
|
|
||||||
} else {
|
|
||||||
Write-Debug "$($ToggleSwitchReg.Name) is false (count: $count)"
|
|
||||||
return $false
|
return $false
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return $false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user