Expanding System.Object for export to csv

Welcome Forums General PowerShell Q&A Expanding System.Object for export to csv

This topic contains 2 replies, has 2 voices, and was last updated by

2 years, 11 months ago.

  • Author
  • #39319

    Points: 50
    Rank: Member

    I have a script that runs through a list of distribution groups and extracts the members and exports to a csv file.

    It works well except where there is more than one member in the group. The output on the screen shows all the members in the Members Column but the csv file shows system.object[] .

    I have tried using the output-string.trim() with limited success. This does remove the system.object[] but it only returns the first member in the list if there are more than one.

    Scenario #1 – No overloads

    On the console it looks like this:

    Scenario #2 using Output-string.Trim()

    Can you look at the script below and tell me what I need to change to capture all the members so they are correctly exported to the csv?

    $forwards = get-distributiongroup -filter {name -like "*forwarder"} | select-object name

    $forwarders = foreach($group in $forwards)


    group = $group.name
    members = (get-distributiongroupmember $group.name | select-object name -ExpandProperty name | out-string).trim()



    $forwarders | export-csv c:\scripts\csvfiles\mail\forwarders.csv

  • #39320

    Points: 21
    Rank: Member

    Use a join to put all members into one string.

    (Get-ADGroupMember 'domain admins').name -join '; '

  • #39325

    Points: 50
    Rank: Member

    Thanks Dan. That worked perfectly.

The topic ‘Expanding System.Object for export to csv’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort