Ok, i got another issue, probably having to do with not being able to store values properly. The original idea was to get a list of users and get their names separated into two values - givenName
and sn
so that Get-ADUser
cmdlet would be able to use them through it's -Filter
option.
While a great idea and solved, i have may have overlooked the fact that when people have 2 names or surnames, that isnt really an option as you cant predict that into a code easily. Another option i found is the attribute displayName
. As our displayNames are equal to full name of the user, it would be the easiest option. However, i cant seem to successfully store the values from txt file into a variable for it to work.
My code currently looks like this:
Import-Csv -Path C:\temp\users.txt -header "displayName" |
ForEach-Object{ Get-ADUser -Filter "displayName -like '$($_.displayName)'" -Properties givenName, Surname, SamAccountName
} |
Select-Object givenName, Surname, SamAccountName |
Export-CSV C:\Temp\usersexport.csv -NoTypeInformation -Encoding UTF8
- The txt file has a structure like so:
John Smith Jones
Paula Ridley
Veronica Anne Downing
etc...
So we arent really talking about a CSV file and the names of users are each in a separate line.
The import works fine, the issue in my opinion is with the introduction of pickedup value from the file and it not being either an actual string or somehow not being registered by the
-Filter
option.In the code above i have removed a variable that was used to store the values as there was no change even if it was there.
I have also tried specifing the
-Delimiter
"`n" in order to specify the separation of values inside the txt file on new each line, but either i didnt use the write symbol or that doesnt work. EDIT:
The issue that happens after i run my code is my exported CSV file only has the following entry: 
. I have no idea why to be honest and it doesnt change no matter what, but like i said it could entirely be possible that the format in which the names inside the txt file are is faulty.
If i understand correctly, -Filter
runs the given value into a string anyway, so i suppose the issue of txt file names not being specially formated before hands isnt whats causing this.