2026-05-08 21:19:52 +02:00
|
|
|
function Split-RegistryPath {
|
|
|
|
|
param(
|
|
|
|
|
[Parameter(Mandatory)]
|
|
|
|
|
[string]$path
|
|
|
|
|
)
|
|
|
|
|
|
2026-05-09 21:56:58 +02:00
|
|
|
$normalizedPath = [string]$path
|
|
|
|
|
if ([string]::IsNullOrWhiteSpace($normalizedPath)) {
|
2026-05-08 21:19:52 +02:00
|
|
|
return $null
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-09 21:56:58 +02:00
|
|
|
$normalizedPath = $normalizedPath.Trim().Replace('/', '\')
|
|
|
|
|
if ([string]::IsNullOrWhiteSpace($normalizedPath)) {
|
|
|
|
|
return $null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($normalizedPath -notmatch '^(?<hive>HKEY_[^\\]+)(?:\\(?<subKey>.*))?$') {
|
|
|
|
|
return $null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$hiveName = [string]$matches.hive
|
|
|
|
|
|
|
|
|
|
$normalizedSubKey = if ($null -ne $matches.subKey) {
|
|
|
|
|
([string]$matches.subKey).Trim('\\')
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($hiveName.Equals('HKEY_USERS', [System.StringComparison]::OrdinalIgnoreCase) -and -not [string]::IsNullOrWhiteSpace($normalizedSubKey)) {
|
|
|
|
|
if ($normalizedSubKey -match '^(?<mount>[^\\]+)(?:\\(?<rest>.*))?$') {
|
|
|
|
|
$mountName = [string]$matches.mount
|
|
|
|
|
if ($mountName.Equals('.DEFAULT', [System.StringComparison]::OrdinalIgnoreCase)) {
|
|
|
|
|
$remainingSubKey = if ($matches.rest) { [string]$matches.rest } else { '' }
|
|
|
|
|
if ([string]::IsNullOrWhiteSpace($remainingSubKey)) {
|
|
|
|
|
$normalizedSubKey = 'Default'
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$normalizedSubKey = "Default\$remainingSubKey"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-08 21:19:52 +02:00
|
|
|
return [PSCustomObject]@{
|
2026-05-09 21:56:58 +02:00
|
|
|
Hive = $hiveName
|
|
|
|
|
SubKey = $normalizedSubKey
|
2026-05-08 21:19:52 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Get-RegistryRootKey {
|
|
|
|
|
param(
|
|
|
|
|
[Parameter(Mandatory)]
|
|
|
|
|
[string]$hiveName
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
switch ($hiveName.ToUpperInvariant()) {
|
|
|
|
|
'HKEY_CURRENT_USER' { return [Microsoft.Win32.Registry]::CurrentUser }
|
|
|
|
|
'HKEY_LOCAL_MACHINE' { return [Microsoft.Win32.Registry]::LocalMachine }
|
|
|
|
|
'HKEY_CLASSES_ROOT' { return [Microsoft.Win32.Registry]::ClassesRoot }
|
|
|
|
|
'HKEY_USERS' { return [Microsoft.Win32.Registry]::Users }
|
|
|
|
|
'HKEY_CURRENT_CONFIG' { return [Microsoft.Win32.Registry]::CurrentConfig }
|
|
|
|
|
default { return $null }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Get-RegistryFilePathForFeature {
|
|
|
|
|
param(
|
|
|
|
|
[Parameter(Mandatory)]
|
2026-05-09 21:56:58 +02:00
|
|
|
$Feature,
|
|
|
|
|
[switch]$UseSysprepRegFiles
|
2026-05-08 21:19:52 +02:00
|
|
|
)
|
|
|
|
|
|
2026-05-09 21:56:58 +02:00
|
|
|
$useSysprepLayout = $UseSysprepRegFiles -or $script:Params.ContainsKey('Sysprep') -or $script:Params.ContainsKey('User')
|
|
|
|
|
if ($useSysprepLayout) {
|
2026-05-08 21:19:52 +02:00
|
|
|
return Join-Path (Join-Path $script:RegfilesPath 'Sysprep') $Feature.RegistryKey
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Join-Path $script:RegfilesPath $Feature.RegistryKey
|
|
|
|
|
}
|