Add comprehensive test suite, fix minor issues, rename function and file names to match approved verbs (#708)

This commit is contained in:
Jeffrey
2026-07-19 22:06:07 +02:00
committed by GitHub
parent a7292e4f35
commit 9c033dbf98
116 changed files with 4629 additions and 650 deletions
+54
View File
@@ -0,0 +1,54 @@
# Returns the directory path of the specified user, exits script if user path can't be found
function Get-UserDirectory {
param (
$userName,
$fileName = "",
$exitIfPathNotFound = $true
)
try {
if ($userName -eq "*") {
$rootPaths = @(
(Join-Path $env:SystemDrive 'Users')
(Split-Path -Path $env:USERPROFILE -Parent)
) | Where-Object { -not [string]::IsNullOrWhiteSpace($_) } | Select-Object -Unique
foreach ($rootPath in $rootPaths) {
if (-not (Test-Path -LiteralPath $rootPath -PathType Container)) {
continue
}
$wildcardPath = if ([string]::IsNullOrWhiteSpace($fileName)) {
Join-Path $rootPath '*'
}
else {
Join-Path (Join-Path $rootPath '*') $fileName
}
return $wildcardPath
}
}
$userContext = Resolve-UserProfileContext -UserName $userName
$resolvedUserDirectory = if ($userContext) { $userContext.ProfilePath } else { $null }
if ($resolvedUserDirectory) {
$userPath = if ([string]::IsNullOrWhiteSpace($fileName)) {
$resolvedUserDirectory
}
else {
Join-Path $resolvedUserDirectory $fileName
}
if ((Test-Path -LiteralPath $userPath) -or ((Test-Path -LiteralPath $resolvedUserDirectory -PathType Container) -and (-not $exitIfPathNotFound))) {
return $userPath
}
}
}
catch {
Write-Error "Something went wrong when trying to find the user directory path for user $userName. Please ensure the user exists on this system"
Wait-ForKeyPress
}
Write-Error "Unable to find user directory path for user $userName"
Wait-ForKeyPress
}