Update Invoke-Tiny11Cleanup.ps1

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Michael Moran 2025-10-13 06:26:33 +11:00 committed by GitHub
parent 43eb6fa3dd
commit 435af2c839
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -25,15 +25,48 @@ function Set-RegistryValue {
param ( param (
[string]$path, [string]$path,
[string]$name, [string]$name,
[string]$type, [ValidateSet('REG_SZ','REG_DWORD','REG_BINARY','REG_MULTI_SZ','REG_EXPAND_SZ','REG_QWORD')] [string]$type,
[string]$value [object]$value
) )
try { try {
# Ensure the registry path exists # Ensure the registry path exists
if (-not (Test-Path $path)) { if (-not (Test-Path $path)) {
New-Item -Path $path -Force | Out-Null New-Item -Path $path -Force | Out-Null
} }
& 'reg' 'add' $path '/v' $name '/t' $type '/d' $value '/f' | Out-Null # Convert value to appropriate string for reg.exe
$valueString = $value
switch ($type) {
'REG_DWORD' {
if ($value -isnot [int] -and $value -isnot [uint32]) {
throw "Value for REG_DWORD must be an integer."
}
$valueString = [string]$value
}
'REG_QWORD' {
if ($value -isnot [int64] -and $value -isnot [uint64]) {
throw "Value for REG_QWORD must be a 64-bit integer."
}
$valueString = [string]$value
}
'REG_BINARY' {
if ($value -isnot [byte[]]) {
throw "Value for REG_BINARY must be a byte array."
}
$valueString = ($value | ForEach-Object { $_.ToString("X2") }) -join ''
}
'REG_MULTI_SZ' {
if ($value -isnot [string[]]) {
throw "Value for REG_MULTI_SZ must be a string array."
}
$valueString = $value -join '\0'
}
'REG_SZ' {}
'REG_EXPAND_SZ' {}
default {
throw "Unsupported registry type: $type"
}
}
& 'reg' 'add' $path '/v' $name '/t' $type '/d' $valueString '/f' | Out-Null
Write-Output "Set registry value: $path\$name" Write-Output "Set registry value: $path\$name"
} catch { } catch {
Write-Output "Error setting registry value: $_" Write-Output "Error setting registry value: $_"