Set-StrictMode -Version Latest $ErrorActionPreference = 'Stop' # 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 }