locked
List Ad Groups along with Membership in csv with each group in it's own column RRS feed

  • Question

  • I came across this link which puts all the users or nest groups in column A along with the name of the group in Column B, so I believe that there may be something there in the right direction.

    Basically I would like to run a script that searches through an OU, it would then output a csv file that would list the name of each group and the users of that group including any nested groups, with each one in it;s own column

    Example

    Group A | Group B | Group C

    Joe         | Joe        |   Group A

    Jill          | Bob       |

    Bob        |             |

    Currently I have been using the following scrip, which will print to screen only and errors on the nested groups

    Import-Module ActiveDirectory

    $Groups = Get-ADGroup -Properties * -Filter * -SearchBase  XXXXXXXXX

    Foreach($Group In $Groups)
    {
       Write-Host $Group.Name
       Write-Host "-------------"
       $Users = $Group.Members
       foreach ($User in $Users)
         {
            get-aduser $User | select name
         }
        Write-Host " "
    }

    Any help would be appreciated as I am an extreme powershell beginner

    Thursday, November 1, 2018 5:28 PM

Answers

  • You will have to create a custom script that builds a custom output in that form.  The format is NOT a csv it is just a table.  It cannot be done automatically with any command.


    \_(ツ)_/

    • Marked as answer by jrv Friday, November 9, 2018 7:49 AM
    Thursday, November 1, 2018 7:49 PM

All replies

  • You will have to create a custom script that builds a custom output in that form.  The format is NOT a csv it is just a table.  It cannot be done automatically with any command.


    \_(ツ)_/

    • Marked as answer by jrv Friday, November 9, 2018 7:49 AM
    Thursday, November 1, 2018 7:49 PM
  • Hi,

    "Get-ADGroupMemeber" cmdlet can also help you get what you want.

    $Groups = Get-ADGroup -Filter *  -SearchBase 'OU=,DC=,DC='
    
    $Results = foreach( $Group in $Groups ){
    
        Get-ADGroupMember -Identity $Group | foreach {
    
            [pscustomobject]@{
    
                GroupName = $Group.Name
    
                Name = $_.Name
    
                }
    
            }
    
        }
    
    $Results | Export-Csv $filepath

    Best Regards,

    Lee


    Just do it.

    Friday, November 2, 2018 6:25 AM
  • Lee,

    Thank you for you help, the script you provided is great, however it lists all the groups in Column A and then the Users in Column B.  Do you have a recommendation as to how we can edit the provided script to put the group name in a separate column and then list each user in the group below the name, with each subsequent group having it's own column?

    Thank you,

    Kevin

    Friday, November 2, 2018 12:59 PM
  • Lee,

    Thank you for you help, the script you provided is great, however it lists all the groups in Column A and then the Users in Column B.  Do you have a recommendation as to how we can edit the provided script to put the group name in a separate column and then list each user in the group below the name, with each subsequent group having it's own column?

    Thank you,

    Kevin

    As jrv stated, you will need to build the script to do what you are asking.

    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''

    Friday, November 2, 2018 3:44 PM