none
Extract Members List of "Selected AD Groups" :: Input: CSV File :: OUTPUT: CSV File (URGENT REQUIREMENT) RRS feed

  • Question

  • Hello Everyone,

    I am looking for a script which extracts AD Group Members (sourced from CSV/TXT file) and Output to CSV/TXT file.

    Can someone help me finding customized script to solve the purpose.

    Quick response is much much appreciated.

    Thanks & Regards,

    Amit Kumar

    Sunday, July 27, 2014 8:39 AM

All replies

  • Hi

    CSV look like this

    GroupName
    FirstGroup
    SecondGroup

    PowerShell is this

    Import-Module Activedirectory
    $Groups=Import-Csv -Path "C:\Users\seimi\Documents\ADGroups.csv"
    foreach ($Entry in $Groups) {
        $Path="C:\Users\seimi\Documents\"+ $Entry.groupname +".csv"
        Get-ADGroupMember -Identity $entry.groupname | Export-Csv -Path $Path -Delimiter ";"
    }


    Seidl Michael | http://www.techguy.at | twitter.com/techguyat | facebook.com/techguyat

    Monday, July 28, 2014 7:55 AM
  • Thanks for he script Michael. I appreciate the assistance however the requirement is slightly different.
    In your script it looks like it is creating single separate file (CSV) for each group. I am looking for a script which generates SINGLE OUTPUT file in following format.

    GroupName    GroupMembers
    ----------------------------
    ADGroup1    Member1,Member2,Member3
    ADGroup2    Member1,Member2,Member3
    ADGroup3    Member1,Member2,Member3

    Could you please tweak the script to provide the above output.

    Thank You Very much in advance !!

    Regards,
    Amit Kumar Rao

    Monday, July 28, 2014 3:25 PM
  • Create a CSV with your headers and use this

    Import-Module Activedirectory
    $Groups=Import-Csv -Path "C:\Users\seimi\Documents\ADGroups.csv"
    foreach ($Entry in $Groups) {
        $Path="C:\Users\seimi\Documents\"+ $Entry.groupname +".csv"
        $Users=(Get-ADGroupMember -Identity $entry.groupname | select -ExpandProperty Name) -join ","
        Add-Content -Path "C:\Users\seimi\Documents\PipeGroup.csv" -Value ($Entry.groupname +";" + $Users)
    }


    Seidl Michael | http://www.techguy.at | twitter.com/techguyat | facebook.com/techguyat

    Wednesday, July 30, 2014 9:24 AM