Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

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

Reply
 
Old 04-07-2008   #1 (permalink)
Tolli


 
 

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
Old 04-08-2008   #2 (permalink)
Kiron


 
 

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
Old 04-08-2008   #3 (permalink)
Kiron


 
 

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
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46