Find group membership

Welcome Forums General PowerShell Q&A Find group membership

Viewing 3 reply threads
  • Author
    Posts
    • #183819
      Participant
      Topics: 12
      Replies: 55
      Points: 246
      Rank: Participant

      Hi Jason,

      I am using your script to find the nested group membership at the below link:

      https://github.com/JasonRobertson/PowerShell/blob/master/Get-NestedADGroupMember/Get-NestedADGroupMember.ps1

      however on line 93:

      Foreach ($Member in (Get-ADGroupMember -Identity $Identity))

      It does not find group members from groups in other domains. I added a paramter to except the domain name also in this line.

      However, I get the below error:

      Cannot compare "CN=AdminGroup,OU=Sales,DC=lab,DC=net" because it is not IComparable.
      At line:118 char:13
      + If ($Group -gt 0){
      + ~~~~~~~~~~~~
      + CategoryInfo : InvalidOperation: (:) [], RuntimeException
      + FullyQualifiedErrorId : NotIcomparable


      However I have permission on this group and can see it from the GUI. This happens even I do not modify the script and run it. Any way to resolve this issue? This is not a permission issue.

    • #183930
      Participant
      Topics: 0
      Replies: 115
      Points: 433
      Helping Hand
      Rank: Contributor

      Hey TechSavy,

      If($Group.Count -gt 0){

      Looks like a typo occurred.

    • #183945
      Participant
      Topics: 12
      Replies: 55
      Points: 246
      Rank: Participant

      Thanks Jason. Using the script, the groups are showing up within the {  } brackets. Instead of the { }, how can we separate the nested groups into different columns to be output to a csv file?

    • #183966
      Participant
      Topics: 12
      Replies: 55
      Points: 246
      Rank: Participant

      Hi Jason,

      In your function I added a parameter [string]$server and updated line 93 to accept this parameter as shown below:

      foreach($member in (Get-ADGroupMember -identity $identity -Server $server)

      I am running the below code:

      @Results=@() 
      foreach($group in ( Import-csv C:\Users\grouplist.csv))
      { 
      $obj=[PSCustomObject]@{ 
      GroupName=$group.GroupName 
      NestedGroups=Get-NestedADGroupMember -identity $group.GroupName -Server $group.DomainName -Listgroups | Select -ExpandProperty Name
      } 
      $Results+=$Obj 
      } 
      $Results | Export-csv C:\Users\results.csv -NoTypeInformation -Append

      However the groups which have more than one nested groups are showing as below:

      AdminGroup               System.Object[]

      How to resolve this?

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