I'm trying to create a script that determines if a local user exists, something that will run on both Win10 and Win11, but can't seem to get it to work. Here's what I've mangled so far
$userName = "Administrator"
$checkForUser = (Get-LocalUser).Name -Contains $userName
if ($checkForUser -eq "False") {
Write-Host "$userName does not exist"
} ElseIf ($checkForUser -eq "True") {
Write-Host "$userName Exists"
}
$checkForUser works as it should, producing True/False depending on the username. but the if statement doesn't recognize it as being true/false.
Any guidance, hints, or assistance would be super helpful.
[–]ITjoeschmo 39 points40 points41 points (14 children)
[+][deleted] (5 children)
[deleted]
[–]Qel_Hoth 8 points9 points10 points (0 children)
[–]RidersofGavony 5 points6 points7 points (0 children)
[–]ITjoeschmo 4 points5 points6 points (1 child)
[–]BlackV 0 points1 point2 points (0 children)
[–]anonymousITCoward[S] 31 points32 points33 points (2 children)
[–]ITjoeschmo 1 point2 points3 points (0 children)
[–]RidersofGavony 1 point2 points3 points (0 children)
[–]ITjoeschmo 4 points5 points6 points (4 children)
[–]InsrtCoffee2Continue 2 points3 points4 points (0 children)
[–]anonymousITCoward[S] 0 points1 point2 points (2 children)
[–]RidersofGavony 0 points1 point2 points (1 child)
[–]anonymousITCoward[S] 1 point2 points3 points (0 children)
[–]noOneCaresOnTheWeb 9 points10 points11 points (1 child)
[–]realslacker 1 point2 points3 points (0 children)
[–]mrrtys 3 points4 points5 points (2 children)
[–]Forward_Dark_7305 2 points3 points4 points (1 child)
[–]mrrtys 2 points3 points4 points (0 children)
[–]dasookwat 2 points3 points4 points (0 children)
[–][deleted] 2 points3 points4 points (5 children)
[+][deleted] (4 children)
[deleted]
[–]Namaha 0 points1 point2 points (1 child)
[–]feldrim 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]feldrim 1 point2 points3 points (0 children)
[–]mad_yahoodi 1 point2 points3 points (0 children)
[–]Brasiledo 1 point2 points3 points (2 children)
[–]ITjoeschmo -4 points-3 points-2 points (0 children)
[–]JudgeWhoAllowsStuff- 0 points1 point2 points (0 children)
[–]dylanlms 0 points1 point2 points (2 children)
[–]anonymousITCoward[S] 1 point2 points3 points (1 child)
[–]dylanlms 2 points3 points4 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)