get samaccountname from displayname

This topic contains 1 reply, has 1 voice, and was last updated by  Wilfredo Perez 2 years, 7 months ago.

  • Author
    Posts
  • #21772

    Wilfredo Perez
    Participant

    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

    Wilfredo Perez
    Participant

    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 }

You must be logged in to reply to this topic.