![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| add user to group /group scope - Global /Group type - Security | PowerShell | |||
| Get-Content and Group-Object | PowerShell | |||
| Group Policy Object Editor? | Vista account administration | |||
| Using group-object | PowerShell | |||
| Group output getting elided | PowerShell | |||