feat(branding): registry helper + Pester harness

This commit is contained in:
sysadmin
2026-06-09 14:08:34 +01:00
parent 73d6611ab5
commit 7de5262c43
2 changed files with 38 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
Set-StrictMode -Version Latest
# Write a registry value under an arbitrary hive root (a live HKLM:/HKCU: path
# OR a loaded offline hive exposed as a PSDrive). Creates intermediate keys.
function Set-SmRegValue {
param(
[Parameter(Mandatory)][string]$Root,
[Parameter(Mandatory)][string]$SubKey,
[Parameter(Mandatory)][string]$Name,
[Parameter(Mandatory)][ValidateSet('String','ExpandString','DWord','Binary')][string]$Type,
[Parameter(Mandatory)]$Value
)
$key = Join-Path $Root $SubKey
if (-not (Test-Path $key)) { New-Item -Path $key -Force | Out-Null }
New-ItemProperty -Path $key -Name $Name -PropertyType $Type -Value $Value -Force | Out-Null
}

View File

@@ -0,0 +1,22 @@
#Requires -Modules @{ ModuleName='Pester'; ModuleVersion='5.0.0' }
Describe 'Set-SmRegValue' {
BeforeAll {
. "$PSScriptRoot\..\branding\lib\RegistryHelpers.ps1"
$script:root = 'HKCU:\Software\SilverMetalTest'
if (Test-Path $script:root) { Remove-Item $script:root -Recurse -Force }
}
AfterAll {
if (Test-Path $script:root) { Remove-Item $script:root -Recurse -Force }
}
It 'creates the key path and writes a string value' {
Set-SmRegValue -Root $script:root -SubKey 'A\B' -Name 'Greeting' -Type String -Value 'hi'
(Get-ItemProperty "$script:root\A\B").Greeting | Should -Be 'hi'
}
It 'writes a dword value' {
Set-SmRegValue -Root $script:root -SubKey 'A' -Name 'Flag' -Type DWord -Value 1
(Get-ItemProperty "$script:root\A").Flag | Should -Be 1
}
}