Get-Content -Path "C:\Temp\users.txt" | % {Get-ADUser -Identity $_} | Select-Object -Property SamAccountName, DistinguishedName
To put that into a csv file again:Get-Content C:\Temp\users.csv | % {Get-ADUser -Identity $_} | Select-Object -Property SamAccountName, DistinguishedName | Export-Csv -Path "C:\Temp\export.csv" -NoTypeInformation
Open in new window
Nearly works but because I've put the wildcard in, it's trying to return every AD object! What filter do I need so it only looks at what's in the CSV file?