Question about Export-CSV

Welcome Forums General PowerShell Q&A Question about Export-CSV

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 7 years ago.

  • Author
  • #5075

    Points: 0
    Rank: Member

    by Porthos at 2012-09-05 06:23:57

    Hi everyone, I am quite new to powershell and am looking for some help with a script I am trying to export to CSV.

    I am trying to get a thorough listing of all users in a group including their membership in all nested groups. This script gives me the thorough information I am looking for. However, my only problem is when I try exporting this to csv, I do not get the information displayed on the screen.

    I get something that looks like this in the CSV...

    Count Length LongLength Rank SyncRoot IsReadOnly IsFixedSize IsSynchronized
    24 24 24 1 System.Object[] FALSE TRUE FALSE
    37 37 37 1 System.Object[] FALSE TRUE FALSE

    I tried using the Out-File command, that works...but I definitely need this to be a delimited file for sorting and reporting.

    Any ideas?

    Thanks in advance!

    $g = Get-QADGroup "DCI\Enterprise Admins" -SizeLimit 0 | Foreach-Object{
    $group = $_
    Get-QADGroupMember $_ -SizeLimit 0 -Type User | Select-Object @{n='GroupName';e={$group.Name}},Name,LogonName

    $g1 = Get-QADGroupMember "DCI\Enterprise Admins" -Indirect -Type Group | Foreach-Object {
    $ngroup = $_
    Get-QADGroupMember $_ | Select-Object @{n='GroupName';e={$ngroup.Name}},Name,LogonName

    $($g,$g1) | export-csv c:\script\testing.csv -NoTypeInformation

    by poshoholic at 2012-09-05 06:54:35

    The problem is that you're exporting two collections to a CSV file, not the contents of one collection (which is really what you want to do). Try this instead:

    (@($g) + @($g1)) | Export-Csv C:\script\testing.csv -NoTypeInformation

    That will combine $g and $g1 into one large collection, even if either of them contains only one member, and then it will export the contents of that collection to CSV.

    by Porthos at 2012-09-06 06:17:01

    Dang that was pretty simple!

    Thanks for the info!

    by poshoholic at 2012-09-07 04:57:07

    I'm glad that resolved your issue, and always happy to help! 🙂

The topic ‘Question about Export-CSV’ is closed to new replies.