none
Export to CSV no showing all data RRS feed

  • Question

  • Hi

    I want to export all global groups with an m in it to Excel.

    foreach($group in (Get-ADGroup -filter "name -like 'G*m*'")){Get-ADGroupMember -Identity $group | select @{n='GroupName';e={$group.name}},samaccountname,name}

    in powershell i get a list with all the groups and there members . So now i want to export to Excel:

    foreach($group in (Get-ADGroup -filter "name -like 'G*m*'")){Get-ADGroupMember -Identity $group | select @{n='GroupName';e={$group.name}},samaccountname,name | export-csv -path d:\groupswithM.csv -Delimiter ";"}

    All i get in my sheet is the last group in my variable. 

    help I want the same output that i get exported to an excel sheet! Help.

    thx in advance.

    Wednesday, September 11, 2019 2:45 PM

All replies

  • Are you saying you want a list of global groups, or are you saying you want to enumerate the members of the global groups? That's not clear to me from your description.

    Can you give an example of what you are expecting your output to look like?


    -- Bill Stewart [Bill_Stewart]

    Wednesday, September 11, 2019 4:18 PM
    Moderator
  • Hi Opu5,

    Im' thinking that your pb is just the coding. Try like this :

    $result = foreach($group in (Get-ADGroup -filter "name -like 'G*m*'"))
        {
        Get-ADGroupMember -Identity $group | Select-Object @{n='GroupName';e={$group.name}},SamAccountname,Name 
        } 
    
    $result | Export-Csv -path d:\groupswithM.csv -Delimiter ";"

    Do something in the foreach loop, put the result in a variable an dthen use the varaible to do other tasks, like export in a .csv file.

    I guess you checked that your foreach loop got you something.

    Olivier.

    Note : it's not the only method to feed a variable.

    Wednesday, September 11, 2019 5:35 PM
  • My best guess at the point of the question.

    Get-ADGroup -filter "name -like 'G*m*'" -PipelineVariable grp |
        Get-ADGroupMember |
        Select-Object @{n='GroupName';e={$grp.name}}, samaccountname, name | 
        export-csv d:\groupswithM.csv -Delimiter ';'


    \_(ツ)_/

    Wednesday, September 11, 2019 5:36 PM