samaccountname from distingiuishedname

Welcome Forums General PowerShell Q&A samaccountname from distingiuishedname

Viewing 3 reply threads
  • Author
    Posts
    • #194471
      Participant
      Topics: 1
      Replies: 2
      Points: -4
      Rank: Member

      Hi, started learning Powershell this week and building a script to pull information off the AD.

      I search an AD group for members, then need to get their manager, then the managers email.

      I can get the distinguished name of the manager but for the email lookup I need their AD name.

      Script so far:

      $Members = Get-ADGroupMember “DDM_Users” | select-object -ExpandProperty samaccountname

      $ManagerArray = @()

      foreach($Member in $Members){

      $ManagerDN += Get-ADUser $Member -properties manager | Select-Object -expandproperty manager
      $Manager = get-aduser $ManagerDN | select-object -expandproperty samaccountname

      }

      This might look all kinds of wrong (probably does) but it’s driving me crazy and I can’t figure out how to get what I need!

    • #194504
      Participant
      Topics: 5
      Replies: 7
      Points: 98
      Rank: Member
      Jonny, try this:
      $Members = Get-ADGroupMember "DDM_Users" | select-object -ExpandProperty samaccountname
      
      foreach($member in $members){get-aduser $member -properties * | Select-Object @{Name="ManagerEmail";Expression={(get-aduser -property emailaddress $_.manager).emailaddress}}}
    • #194534
      Participant
      Topics: 1
      Replies: 2
      Points: -4
      Rank: Member

      I’ll give it a try in the morning when I’ve got the AD network back 🙂

    • #194621
      Participant
      Topics: 1
      Replies: 2
      Points: -4
      Rank: Member

      This works and obviously I can change the emailaddress field to any property I like as well! Now as I continue learning it I can understand how you did it 😀

      Thank you very much!

Viewing 3 reply threads
  • The topic ‘samaccountname from distingiuishedname’ is closed to new replies.