I have a variable with a list of first names and a variable with a list of last names.
I need to create a get-aduser command that will compare these values and spit out the same account name and for some reason I’m having a hard time wrapping my head around this. Probably because it is early!
Please, always when you get errors you should share the complete error message as well. And when you post code or error messages or sample date or console output you should format it as code using the code tags “PRE”. Thanks in advance. Read Me Before Posting! You’ll be Glad You Did!
If I got you right you have to use a nested loop as you don’t have relations between the given names and surnames. Regardless of that you should always use a searchbase as this limits the stress you put on your DC with a query. So something like this could be a start for you:
Olaf,
Sorry I don’t know what happened here as I replied to this message this morning.
First Thank you as it gives me enough of the data to easily complete what I need!
Second and I’m not concerned about I do get a bunch of errors when executing it stating:
EDIT:
Now that I look at your code it looks like the error is from the mismatch of the data it is searching SurName and different GivenName. I believe I should be able to resolve this by just adding -ErrorAction SilentlyContinue to the Get-ADUser command.
Looks to me like you have a syntax error in your filter string. You have to be careful to choose the right quotes for the filter string. Outside the string you use double quotes and inside single quotes … like this: -Filter “enabled -eq ‘$true’ -and surname -eq ‘$surName’ -and givenname -like ‘$givenName’”
Olaf strange the -ErrorAction SilentlyContinue did not do as I thought and I have the string EXACTLY as you have mentioned it both times. Where I see the error is when it seems like a name does not match since it is going through every fname with the single lname.