wigsc
asked on
Get DN from SAMAccountName
Hi,
I'm looking to do something that I assume is quite simple for someone in the know. I have a CSV file with a list of SAMAccountNames and from that I want to use Powershell to output a list of Distinguished Names. Anyone know how?
Thanks.
I'm looking to do something that I assume is quite simple for someone in the know. I have a CSV file with a list of SAMAccountNames and from that I want to use Powershell to output a list of Distinguished Names. Anyone know how?
Thanks.
Can't test it at the moment, but that should do it:
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?