get samaccountname from displayname

Welcome Forums General PowerShell Q&A get samaccountname from displayname

This topic contains 1 reply, has 1 voice, and was last updated by

 
Participant
3 years, 9 months ago.

  • Author
    Posts
  • #21772

    Participant
    Points: 0
    Rank: Member

    I have a list of user names ex. last name, First name. Here is my script

    foreach ($user in (Get-Content -Path U:\Morningstar\Morningstar.txt))
    {Get-ADUser -filter { DisplayName -like "$user" }} | samaccountname

    The problem is the -filter part.

  • #21773

    Participant
    Points: 0
    Rank: Member

    it's working now:

    Here is the script:

    foreach ($user in (Get-Content -Path U:\Morningstar\Morningstar.txt))
    {Get-ADUser -filter { DisplayName -like $user } | Select SamAccountName }

The topic ‘get samaccountname from displayname’ is closed to new replies.