feat: add automated environment report export (#5025)

* feat: add automated environment report export

* refactor: address code review comments

* fix: refresh toggle state in environment report

* fix: surface environment report read failures

* test: make registry failure explicit

---------

Co-authored-by: Chris Titus <contact@christitus.com>
This commit is contained in:
Omar
2026-09-02 17:03:22 -05:00
committed by GitHub
co-authored by Chris Titus
parent 4a1db91e3f
commit 7ee5be3d2f
12 changed files with 704 additions and 15 deletions
+24 -11
View File
@@ -1,23 +1,32 @@
Function Get-WinUtilToggleStatus ($ToggleSwitch) {
Function Get-WinUtilToggleStatus {
param(
$ToggleSwitch,
[switch]$BypassCache,
[switch]$StopOnReadError
)
$ToggleSwitchReg = $sync.configs.tweaks.$ToggleSwitch.registry
if ($null -eq $sync.ToggleStatusCache) {
$sync.ToggleStatusCache = @{}
if (-not $BypassCache) {
if ($null -eq $sync.ToggleStatusCache) {
$sync.ToggleStatusCache = @{}
}
if ($sync.ToggleStatusCache.ContainsKey($ToggleSwitch)) {
return [bool]$sync.ToggleStatusCache[$ToggleSwitch]
}
}
if ($sync.ToggleStatusCache.ContainsKey($ToggleSwitch)) {
return [bool]$sync.ToggleStatusCache[$ToggleSwitch]
}
$readErrorAction = if ($StopOnReadError) { "Stop" } else { "Continue" }
if (-not (Get-PSDrive -Name HKU -ErrorAction SilentlyContinue)) {
New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS | Out-Null
New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS -ErrorAction $readErrorAction | Out-Null
}
foreach ($regentry in $ToggleSwitchReg) {
if (Test-Path $regentry.Path) {
$regstate = (Get-ItemProperty -Path $regentry.Path).$($regentry.Name)
if (Test-Path $regentry.Path -ErrorAction $readErrorAction) {
$regstate = (Get-ItemProperty -Path $regentry.Path -ErrorAction $readErrorAction).$($regentry.Name)
} else {
$regstate = $null
}
@@ -30,11 +39,15 @@ Function Get-WinUtilToggleStatus ($ToggleSwitch) {
}
if ($regstate -ne $regentry.Value) {
$sync.ToggleStatusCache[$ToggleSwitch] = $false
if (-not $BypassCache) {
$sync.ToggleStatusCache[$ToggleSwitch] = $false
}
return $false
}
}
$sync.ToggleStatusCache[$ToggleSwitch] = $true
if (-not $BypassCache) {
$sync.ToggleStatusCache[$ToggleSwitch] = $true
}
return $true
}