locked
Import AD groups from csv and export their members RRS feed

  • Question

  • Hello All,

    Having a bit of an issue doing this with bulk import. No issues with running Get-ADGroupMember on a single group but with import... I want to pull my hair out. Not sure if I need to create a custom object or what but I need to import a csv with say 100 groups and export their members. The issue that I am having is that on the export... I need to have the group name so I know what group theyre members of. Also, I need to get the nested groups (not a recursive to see the nested groups members but the group object itself) as well as any orphaned SIDs. 

    I have been researching and testing for weeks... at my wits end.. please help!

    Wednesday, September 2, 2015 10:30 PM

Answers

  • Here's an example you can play with that will show you a method of adding the group name to the export:

    Get-ADGroup -Filter "Name -like 'Test Group *'" | ForEach {
    
        $groupName = $_.Name
    
        Get-ADGroupMember -Identity $_ | Select @{N='GroupName';E={$groupName}},*
    
    } | Export-Csv .\groupMemberships.csv -NoTypeInformation


    Thursday, September 3, 2015 1:56 AM

All replies

  • You need to post your script with any error messages.

    \_(ツ)_/

    Wednesday, September 2, 2015 11:12 PM
  • This is the only one that I have gotten to work but as you can probably tell... the export doesn't show the groups name that they are members of

    Import-Csv {PATH} |
    % {
    Get-ADGroupMember -Identity $_.groupName |
    select name, objectClass } |
    Export-Csv {PATH} -NoTypeInformation
    

    Wednesday, September 2, 2015 11:28 PM
  • Also, I can't figure out how to identify groups members that are orphaned SIDs. Furthermore, how to remove SIDs from group membership (I know a bit in the weeds) but still an issue... sigh
    Thursday, September 3, 2015 1:54 AM
  • Here's an example you can play with that will show you a method of adding the group name to the export:

    Get-ADGroup -Filter "Name -like 'Test Group *'" | ForEach {
    
        $groupName = $_.Name
    
        Get-ADGroupMember -Identity $_ | Select @{N='GroupName';E={$groupName}},*
    
    } | Export-Csv .\groupMemberships.csv -NoTypeInformation


    Thursday, September 3, 2015 1:56 AM
  • working with your example... i was able to put this together (which after testing, gets me 90% of the way there)

    Import-Csv {PATH} |
    % {
    $GroupName = (Get-ADGroup $_.groupName).name
    Get-ADGroupMember -Identity $_.groupName } |
    select @{N='Group';E={$GroupName}}, name, objectClass |
    Export-Csv {PATH} -NoTypeInformation
    

    The only thing that I am missing is the ability to include orphaned SIDs that are members of the groups. Is this possible?

    Thursday, September 3, 2015 11:34 AM