How to output many people's SamAccountName in batch by powershell

Jacky Guo 21 Reputation points
2021-03-16T08:50:32.997+00:00

I just can find one by one

Get-aduser -filter 'Name -like "displayname" ' -Properties * | Format-table Name,SamAccountName,EmailAddress -A

Windows for business Windows Server User experience PowerShell
{count} votes

Accepted answer
  1. Anonymous
    2021-03-16T13:53:36.343+00:00

    Hi,

    Suppose you have an array of displaynames $displaynames, then you can do something like the following

    $displaynames = ’dn1‘,'dn2','dn3'  
    foreach($displayname in $displaynames)  
    {  
        Get-ADUser -Filter {displayname -eq $displayname} -Properties EmailAddress | Format-table Name,SamAccountName,EmailAddress -AutoSize  
    }  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.