Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,31 @@ function Get-RegUserPaths {
)

$regPattern = 'Volatile Environment|AME_UserHive_'
if ($NoDefault) {$regPattern = "$regPattern[1-9].*"}
$initPaths = Get-ChildItem -Path "Registry::HKU" | Where-Object { $_.Name -match "S-[0-9-]+(?!.*_)|$regPattern" }
$defaultPathPattern = '(^|\\)\.DEFAULT$|(^|\\)AME_UserHive_Default$'

# If the 'Volatile Environment' key exists, that means it is a proper user. Built in accounts/SIDs don't have this key
$initPaths = Get-ChildItem -Path "Registry::HKU" |
Where-Object {
$keyName = $_.Name
$isUserHive = $keyName -match 'S-[0-9-]+(?!.*_)' -or $keyName -match 'AME_UserHive_'
$isDefaultHive = $keyName -match $defaultPathPattern

$isUserHive -and (-not ($NoDefault -and $isDefaultHive))
}

# If the 'Volatile Environment' key exists, that means it is a proper user. Built in accounts/SIDs don't have this key.
$paths = @()
if (!$DontCheckEnv) {
foreach ($userKey in $initPaths) {
if ((Get-ChildItem -Path $userKey.PsPath | Where-Object { $_ -match $regPattern }).Count -ne 0) {
$hasUserMarker = Get-ChildItem -Path $userKey.PsPath | Where-Object { $_.Name -match $regPattern }
if ($hasUserMarker) {
$paths += $userKey
}
}
} else {
$paths = $initPaths
}

return $paths
return @($paths)
}

Export-ModuleMember -Function Get-RegUserPaths
Loading