Can someone tell me why the -or does not work. If I run the code the first output is administrator which returns true but when it gets to the kahuna account it still returns false not true.
(Get-LocalUser).Name | Out-File C:\localusers.txt
ForEach ($User in Get-Content C:\localusers.txt)
{
If ($User -match "administrator" -or "kahuna")
{
Write-Host True
}
Else
{
Write-Host False
}
}
I get
True, False, False, False, False
Here are the accounts listed in order they appear
administrator, DefaultAccount, Guest, Kahuna, PCUser
Try
If ($User -match "administrator" -or $User -match "kahuna")
Your -or
operator doesn't tie the values of the previous operator together. You need to specify a 2nd conditional operator after -or
I believe.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With