Windows Vista Forums

Group-Object and getting the full GroupInfo (Group) output.
  1. #1


    Tolli Guest

    Group-Object and getting the full GroupInfo (Group) output.

    I have a bunch of files that contain users one per line. I want to use
    get-content | group-object to get the common occurences of each user one per
    line, showing the total and then the list of files that contain the user.

    If there are more files than will fill the screen, the group column gets
    truncated (see the ... below):
    # Get-Content "c:\temp\Users\*.txt" | group-object

    Count Name Group
    ----- ---- -----
    20 bspadmin {appu1g1.txt, Copy (2) of appu1g1.txt, Copy
    (2) of appu1g2.txt, Copy (3) of appu1g1....
    20 oracle {appu1g1.txt, Copy (2) of appu1g1.txt, Copy
    (2) of appu1g2.txt, Copy (3) of appu1g1....
    20 u141562 {appu1g1.txt, Copy (2) of appu1g1.txt, Copy
    (2) of appu1g2.txt, Copy (3) of appu1g1....

    If I have a few files they fit on the screen:
    5 u602188 {appu1b6.txt, appu1g1.txt, appu1g2.txt,
    appu470.txt, dbsu1g1.txt}
    5 u452413 {appu1b6.txt, appu1g1.txt, appu1g2.txt,
    appu470.txt, dbsu1g1.txt}
    4 u475854 {appu1b6.txt, appu1g1.txt, appu1g2.txt,
    appu470.txt}
    4 u445383 {appu1b6.txt, appu1g1.txt, appu1g2.txt,
    appu470.txt}
    4 u485710 {appu1b6.txt, appu1g1.txt, appu1g2.txt,
    appu470.txt}



    I would really like to export ALL this data to a csv file, but using I get
    garbage for output:

    Get-Content "c:\temp\Users\*.txt" | Group-Object | Sort-Object count -desc |
    Export-Csv -path c:\temp\foo.csv

    #TYPE Microsoft.PowerShell.Commands.GroupInfo
    Values Count Group Name
    System.Collections.ArrayList 5 System.Collections.ObjectModel.Collection`1[System.Management.Automation.PSObject] u151170
    System.Collections.ArrayList 5 System.Collections.ObjectModel.Collection`1[System.Management.Automation.PSObject] u152379

    How can I get usable information for output?
    Thanks,
    Tolli

      My System SpecsSystem Spec

  2. #2


    Kiron Guest

    Re: Group-Object and getting the full GroupInfo (Group) output.

    # just noticed you wanted file names not the full path. Change...
    expression = {$_.Group | % {$_.path}}} |
    # to...
    expression = {$_.Group | % {$_.fileName}}} |

    # in the shorter version change...
    @{n = 'FileName'; e = {$_.Group | % {$_.path}}} |
    # to...
    @{n = 'FileName'; e = {$_.Group | % {$_.fileName}}} |

    --
    Kiron

      My System SpecsSystem Spec

  3. #3


    Kiron Guest

    Re: Group-Object and getting the full GroupInfo (Group) output.

    Glad to help Tolli.
    Insert a Where-Object statement to exclude 'blank' lines in the $uniqueUsers assignment:

    # long version...
    $uniqueUsers = get-content $dir\$type | where-object {$_} | sort-object -unique
    # short version...
    $uniqueUsers = gc $dir\$type | ? {$_} | sort -u

    --
    Kiron

      My System SpecsSystem Spec

Group-Object and getting the full GroupInfo (Group) output. problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
add user to group /group scope - Global /Group type - Security Michael PowerShell 2 14 Jul 2009
Get-Content and Group-Object Kam-Hung Soh PowerShell 10 05 Jan 2008
Group Policy Object Editor? Nigel Molesworth Vista account administration 8 11 Jan 2007
Using group-object Marco Shaw PowerShell 16 15 Dec 2006
Group output getting elided Keith Hill [MVP] PowerShell 4 20 Aug 2006