Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Wednesday, March 27, 2013 12:50 PM
I have a series of text files with about 200 usernames per text file. What I'd like to do is execute a simple command from PowerShell to reference the usernames in "TextFile1.txt", grab the DisplayName for those usernames from AD, and export that data to CSV. Is that possible? If so, can someone provide an example?
All replies (3)
Wednesday, March 27, 2013 1:13 PM ✅Answered
Get-Content C:\TextFile1.txt | Get-ADUser -Identity $_ -Properties DisplayName | Select-Object DisplayName | Export-CSV C:\somefile.csv -NoTypeInformation
Something like that should do
If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.
Wednesday, March 27, 2013 1:33 PM ✅Answered
This looks to have done the trick.
Get-Content C:\TextFile.txt | Get-User | Select DisplayName | Export-Csv C:\TextFileDisplayNames.csv -NoTypeInformation
Wednesday, March 27, 2013 2:42 PM
For the series of text files...if they are under one folder....
$files = Get-ChildItem "c:\direcotory\
foreach ($file in $files) {
$users = Get-Content $file.fullname
foreach($user in $users) {
Get-ADUser -Identity $_ -Properties DisplayName | Select-Object DisplayName | Export-CSV C:\somefile.csv -NoTypeInformation
}
}
Hope it helps
Thanks Azam When you see answers please Mark as Answer if Helpful..vote as helpful.