none
Get MemberOf details for a user RRS feed

  • Question

  • Hi All

    I am trying t get a list of users in AD who is part of a group called "AD Group name" and get the users information and the group details like Group membership,DisplayName,description field the user is memberof. I used the below script and got most of the information except for the Groups details.

    Get-ADGroupMember -Identity "AD Group name" -Recursive |
    Where objectclass -eq 'user' |
    Get-ADUser -Properties Displayname,Title,Department |
    Select DistinguishedName,samAccountName,Name,Displayname,Title,Department,MemberOf|
    Export-CSV C:\Users\admin1.csv

    Kindly assist.


    Justin

    • Moved by Bill_Stewart Thursday, January 3, 2019 3:59 PM This is not "scripts on demand"
    Monday, November 5, 2018 8:51 AM

All replies

  • $selectprops = @(
        @{n='GroupName';e={$groupname}},
        'DistinguishedName',
        'samAccountName',
        'Name',
        'Displayname',
        'Title',
        'Department',
        'MemberOf'
    )
    $groupname = 'AD Group name'
    Get-ADGroupMember -Identity $groupname |
        Where objectclass -eq 'user' |
        Get-ADUser -Properties Displayname,Title,Department |
        Select $selectprops |
        Export-CSV C:\Users\admin1.csv


    \_(ツ)_/


    • Edited by jrv Monday, November 5, 2018 8:59 AM
    Monday, November 5, 2018 8:59 AM
  • Hi 

    Thank you. But still i get the same output when i run them. The MemberOf column displays "Microsoft.ActiveDirectory.Management.ADPropertyValueCollection" for all the users. I am trying to get all the group details(Group Name,GroupDisplayName,Group description etc) from the member of tab of the user.


    Justin

    Monday, November 5, 2018 9:08 AM
  • The memberof column needs to be ignored as it can be a very large collection which is why it cannot be directly displayed.

    Look in Gallery for scripts that will do what you are thinking of. Ther ae quite a few.


    \_(ツ)_/

    Monday, November 5, 2018 9:31 AM
  • Thanks. I got a script which works for me. Just that while fetching the data can the groups be added to the next column separated by comma?

    E.g 

    User Groups

    Justin Grp1,Grp2,Grp3

    $users = Get-ADGroupMember -Identity "AD Group name" -Recursive |
    Where objectclass -eq 'user' |
    Get-ADUser -Properties Displayname,Title,Department
    $logfile = "C:\xadmingrp.csv"
    
    foreach($user in $users){
      add-content $logfile $user.Name
      $groups = Get-ADPrincipalGroupMembership $user.SamAccountName 
      foreach($group in $groups){
        add-content $logfile $group.name
      }
    }


    Justin

    Monday, November 5, 2018 9:36 AM
  • You have to use a computed property that joins the array.


    \_(ツ)_/

    Monday, November 5, 2018 9:38 AM