Need Help ADQuery

Welcome Forums General PowerShell Q&A Need Help ADQuery

This topic contains 2 replies, has 3 voices, and was last updated by

Ron
 
Participant
1 year, 11 months ago.

  • Author
    Posts
  • #64500

    Participant
    Points: 6
    Rank: Member

    Dear powershell Gurus 🙂

    I need to combine below results and output in to an csv file . Could some one please help.
    $groupname = "ExampleGroupname"
    $members = get-adgroupmember -identity $groupname
    $memberof = get-adprincipalgroupmembership -identity $groupname

    The result should be like
    Domainname,members,Memberof

  • #64569

    Participant
    Points: 413
    Helping Hand
    Rank: Contributor

    I assume you're asking for more than just one group, right? 😉 You can do a foreach loop and create a PS custom object in this loop. Then you can pipe this to an export-csv.

  • #64579
    Ron

    Participant
    Points: 2
    Rank: Member

    Unless your AD is small and fairly simple, squeezing that info into a csv can be problematic. This should help though. The member commands return objects and you are likely only interested in the samAccountname.

    $members = (get-adgroupmember -identity $groupname | select -expand samaccountname) -join "|"
    $memberof = (get-adprincipalgroupmembership -identity $groupname | select -expand samaccountname) -join "|"
    

    Now you can form a psobject and export to a csv file.

The topic ‘Need Help ADQuery’ is closed to new replies.