Exporting AD group members

Welcome Forums General PowerShell Q&A Exporting AD group members

Viewing 5 reply threads
  • Author
    Posts
    • #243731
      Participant
      Topics: 1
      Replies: 2
      Points: 17
      Rank: Member

      Hello I am getting this error when exporting AD group members

      Error  Get-ADGroupMember : A parameter cannot be found that matches parameter name ‘GroupObjectId’.
      ` <br />$Groups = Get-ADGroup -Filter {name -like "XYZ*"} -SearchBase "OU=Groups,OU=Name1, OU=Name2"<br />foreach ($group in $groups){<br />$group.DisplayName<br />$members = Get-ADGroupMember -GroupObjectId $group.ObjectId -All<br />foreach ($member in $members)<br />{$member | Add-Member -NotePropertyName "Group" -NotePropertyValue ($group.DisplayName)<br />$member | select Group, EmailAddress, DisplayName | Export-Csv ADtest1.csv -NoTypeInformation -Append }<br />}<br />

      Thanks for helping

       

       

      • This topic was modified 2 months ago by Titan81.
    • #243737
      Participant
      Topics: 15
      Replies: 1775
      Points: 3,214
      Helping Hand
      Rank: Community Hero

      Titan, welcome to Powershell.org. Please take a moment and read the very first post on top of the list of this forum: Read Me Before Posting! You’ll be Glad You Did!.

      When you post code, error messages, sample data or console output format it as code, please.
      In the “Text” view you can use the code tags “PRE“, in the “Visual” view you can use the format template “Preformatted“. You can go back edit your post and fix the formatting – you don’t have to create a new one.
      Thanks in advance.

      Normally, you find AD objects, you use -Identity to find the object. There is no -GroupObjectId parameter. Additionally, made some changes to clean the code up a bit, but did not test it:

    • #243740
      Participant
      Topics: 51
      Replies: 209
      Points: 860
      Helping Hand
      Rank: Major Contributor

      How about this, which worked for me…but I couldn’t find a switch “-All” but used “-Recursive”

    • #243761
      Participant
      Topics: 1
      Replies: 2
      Points: 17
      Rank: Member

      Thanks I’ve formatted as recommended.

      Also when I run your script there is a new error

       
      Get-ADGroupMember : A parameter cannot be found that matches parameter name ‘All’.

    • #243812
      Participant
      Topics: 8
      Replies: 568
      Points: 2,170
      Helping Hand
      Rank: Community Hero

      Here’s an example using multiple filters and splatting, I find it easier to read and follow along.

      CSV will have 3 colums: Group, SamAccountName, and EmailAddress

    • #243899
      Participant
      Topics: 1
      Replies: 2
      Points: 17
      Rank: Member

      Thanks this one worked

      It is taking a long time to run thanks for your help

Viewing 5 reply threads
  • You must be logged in to reply to this topic.