mirror of
https://github.com/Raphire/Win11Debloat.git
synced 2026-05-18 19:56:25 +00:00
Starting from this commit, Win11Debloat will automatically create a registry backup every time the script is run. This registry backup can be used to revert any registry changes made by the script.
47 lines
1.4 KiB
PowerShell
47 lines
1.4 KiB
PowerShell
function Test-TargetUserName {
|
|
param(
|
|
[AllowNull()]
|
|
[AllowEmptyString()]
|
|
[string]$UserName
|
|
)
|
|
|
|
$normalizedUserName = if ($null -ne $UserName) { $UserName.Trim() } else { '' }
|
|
|
|
if ([string]::IsNullOrWhiteSpace($normalizedUserName)) {
|
|
return [PSCustomObject]@{
|
|
IsValid = $false
|
|
UserName = $normalizedUserName
|
|
Message = 'Please enter a username'
|
|
}
|
|
}
|
|
|
|
if ($normalizedUserName -eq $env:USERNAME) {
|
|
return [PSCustomObject]@{
|
|
IsValid = $false
|
|
UserName = $normalizedUserName
|
|
Message = "Cannot enter your own username, use 'Current User' option instead"
|
|
}
|
|
}
|
|
|
|
if (-not (CheckIfUserExists -userName $normalizedUserName)) {
|
|
return [PSCustomObject]@{
|
|
IsValid = $false
|
|
UserName = $normalizedUserName
|
|
Message = 'User not found, please enter a valid username'
|
|
}
|
|
}
|
|
|
|
if (TestIfUserIsLoggedIn -Username $normalizedUserName) {
|
|
return [PSCustomObject]@{
|
|
IsValid = $false
|
|
UserName = $normalizedUserName
|
|
Message = "User '$normalizedUserName' is currently logged in. Please sign out that user first."
|
|
}
|
|
}
|
|
|
|
return [PSCustomObject]@{
|
|
IsValid = $true
|
|
UserName = $normalizedUserName
|
|
Message = "User found: $normalizedUserName"
|
|
}
|
|
} |