mirror of
https://github.com/Raphire/Win11Debloat.git
synced 2026-04-03 14:06:27 +00:00
33 lines
719 B
PowerShell
33 lines
719 B
PowerShell
|
|
function CheckIfUserExists {
|
||
|
|
param (
|
||
|
|
$userName
|
||
|
|
)
|
||
|
|
|
||
|
|
if ($userName -match '[<>:"|?*]') {
|
||
|
|
return $false
|
||
|
|
}
|
||
|
|
|
||
|
|
if ([string]::IsNullOrWhiteSpace($userName)) {
|
||
|
|
return $false
|
||
|
|
}
|
||
|
|
|
||
|
|
try {
|
||
|
|
$userExists = Test-Path "$env:SystemDrive\Users\$userName"
|
||
|
|
|
||
|
|
if ($userExists) {
|
||
|
|
return $true
|
||
|
|
}
|
||
|
|
|
||
|
|
$userExists = Test-Path ($env:USERPROFILE -Replace ('\\' + $env:USERNAME + '$'), "\$userName")
|
||
|
|
|
||
|
|
if ($userExists) {
|
||
|
|
return $true
|
||
|
|
}
|
||
|
|
}
|
||
|
|
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"
|
||
|
|
}
|
||
|
|
|
||
|
|
return $false
|
||
|
|
}
|