Hello,
I am trying to create a script that will validate AD credentials and only allow certain users to access the form that this script will open. So I have it prompting to enter login information and that is working great. The problem is where the ** are when I do the or statement it then allows everyone to run the script instead of going to the else command.
so if user4 tries to sign in they should get the DO ERRO ACTION event. however, they are not, they are getting the DO ACTION command. Any help? or need more details?
$cred = Get-Credential
$username = $cred.username
$password = $cred.GetNetworkCredential().password
$CurrentDomain = "LDAP://" + ([ADSI]"").distinguishedName
$domain = New-Object System.DirectoryServices.DirectoryEntry($CurrentDomain,$UserName,$Password)
**if($cred.UserName -eq "USER1" -or "USER2" -or "USER3"){DO ACTION}
Else{DO ERROR ACTION}
Or statements
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: Or statements
Can you give any details? If I say USER1 or USER2 it works fine it’s when I add the third user and so it it does not work. The ** are showing where I am having the problem. Not actually in the script.
Thanks.
Thanks.
Re: Or statements
You must use the match for each instancw and OR the matches.
if( $a -eq 1 -or $a -eq 2){ ...
If you OR them it will always give you true.
1 -or 2
1 -or 3
1 -or 4
All test will always be true.
It is basic logic and it is the part of logic that most fail on because it is not how we take. It is a test. You must test each possibility.
if( $a -eq 1 -or $a -eq 2){ ...
If you OR them it will always give you true.
1 -or 2
1 -or 3
1 -or 4
All test will always be true.
It is basic logic and it is the part of logic that most fail on because it is not how we take. It is a test. You must test each possibility.