get samaccountname from displayname

This topic contains 1 reply, has 1 voice, and was last updated by Profile photo of Wilfredo Perez Wilfredo Perez 1 year, 11 months ago.

  • Author
    Posts
  • #21772
    Profile photo of Wilfredo Perez
    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
    Profile photo of Wilfredo Perez
    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.