Asked by:

Get-ADUser infomration by querying AD after first pulling GivenName and Surname from a CSV file

Question

I have been trying to do something very simple for several hours, and have now got pretty fed up as nothing works and am asking for help. I have tried various iterations by looking at Powershell Help examples and cannibalising others scripts from online,
but currently I have:

You might make a little step back and start with learning the very basics of Powershell from scratch. You cannot properly learn a technology by guessing or sneaking into other peoples code. I'm sure it will pay off for you in the future.

Hmmm. Why does everyone insist on using two code sections when only one is required? It is like using a double negative. The effect and efficiency of the PowerShell design are completely erased. You might as well use VBScript.

Obviously I don't have your experience and sometimes is "working" just good enough. But as usual is your code more sophisticated and lean and efficient. I whish I had your brain. ;-) :-D

Live long and prosper!

(79,108,97,102|%{[char]$_})-join''

Don't take it too seriously. I was just trying to shake up your memory circuits so you think differently about code. Your code is not wrong or even bad. It just misses some things that would accelerate your approach.

It IS a CSV file with just two columns. I have already gone down that route. I created a fresh csv and pasted in the values but it made no difference. I also tried get-content with a text file containing the same values.

You might make a little step back and start with learning the very basics of Powershell from scratch. You cannot properly learn a technology by guessing or sneaking into other peoples code. I'm sure it will pay off for you in the future.

It seems most likely that you do not have a CSV or your CSv has blank entries. You have to take some time and try to understand how each piece works and what that piece is technically. We cannot see your system and cannot guess at what we cannot
see.

OK, so your CSV file does not have headers and you don't use the standard delimiter. You will have to change your code to adapt this. Please have in mind that we cannot see your screen and we don't know your environment. Do you use a space or a tab as
delimiter?

You know what, all I did was to clear the spaces out of the csv file, export-csv to a new file and it worked! I wrote a small script yesterday that was mostly my own (I had to borrow from others online on how to filter on two separate properties together)
which did not work, and the one I posted was after about 50 bits of cannibalisation from other lines of code found online which also failed to work. If the originating file was sorted first, I could have saved myself half day. Just goes to show to look
at the smallest things first. Thanks a lot.

This filter should work and be faster. You can use -like and add a * if you need to. -match is not supported (regex). The doublequotes and singlequotes are required in this order. The $( ) is required to interpret a $object.property
within a string.

You know what, all I did was to clear the spaces out of the csv file, export-csv to a new file and it worked! I wrote a small script yesterday that was mostly my own (I had to borrow from others online on how to filter on two separate properties together)
which did not work, and the one I posted was after about 50 bits of cannibalisation from other lines of code found online which also failed to work. If the originating file was sorted first, I could have saved myself half day. Just goes to show to look
at the smallest things first. Thanks a lot.

Always start by inspecting each component you have contributed. You will get better at this with experience