For the post answered Oct 31 '17 at 13:06:
Q:
I have a .txt file with a bunch of email addresses and I need get corresponding login names and export them into another file.
A:
Get-Content -Path "c:\users-input.txt" | %{ Get-ADUser -Filter {EmailAddress -eq $_} } | Select-Object SamAccountName | Export-CSV -Path "c:\users.csv"
Excellent, concise, single like example. Thanks!
Can you provide an example for outputing multiple attributes of the user accounts (ex: sAMAccountName, userPrincipalName, displayName, mail, userAccountControl) based on the input file being a list of email addresses?
Add the desired property names to the -Properties
retrieved by Get-ADUser
( SAMAccountName
and UserPrincipalName
will already be part of the default property set) and then specify the full property list selected by Select-Object
:
Get-Content -Path "c:\users-input.txt" | %{
Get-ADUser -Filter {EmailAddress -eq $_} -Properties displayName,mail,userAccountControl
} | Select-Object SamAccountName,userPrincipalName,displayName,mail,userAccountControl | Export-CSV -Path "c:\users.csv"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.