Hi there! I have a script for work that runs an lookup in AD for computer names. We have a lot of computers and servers, and so I put a lot of conditions as to which naming conventions to ignore. For some reason, a certain naming convention keeps getting past my original (first) If statement, and passes it onto the next ElseIf’s. Here’s a the part of the code in question.
(#####Comments explain context#####)
The naming convention that is somehow defying the original if statement (which looks for “-” or “_”) is
Non-COE_X999999 (Which contains both of the conditions I’m looking for)
Instead, it goes ahead and tries to query for it in the ElseIf part, and I don’t get why.
If anyone can shed some light on this, that would be great. I don’t know if its the If statement that’s ignoring it, or the ElseIf which is somehow overwriting it, but either its not working right.
Yeah I thought maybe the filter had to do with it. So I tried to do more combinations, all the combinations, and for some reason only some of them work. -contains only works half the time, and I ended up having to seperate them as individual variables like so:
($PCName -like “-” -or $PCName -like “_”)
then I added an -not to make it a NOR statement.
-not(($PCName -like “-”) -or ($PCName -like “_”))
and that works…
Thanks @Evila Osa for your help, because I honestly wasn’t sure if it was just my elseif that was overwriting it… somehow.