Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Group extensions by size

Closed Thread
 
Thread Tools Display Modes
Old 04-09-2007   #1 (permalink)
Ant
Guest


 

Group extensions by size

I have a sample that does extensions by count for my F: drive, but how
do I do this by length instead of count?

get-childitem -r c:\ | group extension | sort-object count -descending
| select -first 10

Thank you in advance

Old 04-09-2007   #2 (permalink)
Jacques Barathon [MS]
Guest


 

Re: Group extensions by size

"Ant" <antgoodlife@gmail.com> wrote in message
news:1176136308.451747.197050@y80g2000hsf.googlegroups.com...
>I have a sample that does extensions by count for my F: drive, but how
> do I do this by length instead of count?
>
> get-childitem -r c:\ | group extension | sort-object count -descending
> | select -first 10


Probably not optimised for a complete drive scan, but basically equivalent
to your sample:

dir -r c:\ | group extension | select @{n="Size";e={($_.group | measure
length -sum).sum}},name | sort size -desc | select -first 10

Jacques

Old 04-09-2007   #3 (permalink)
Ant
Guest


 

Re: Group extensions by size

Thank you, while I am sure this is close, it's throwing this error :
PS F:\> dir -r F:\ | group extension | select @{n="Size";e={($_.group
| measure length -sum).sum}},name | sort size -desc | select -first 10
Select-Object : The term 'measure' is not recognized as a cmdlet,
function, operable program, or script file. Verify the term and try
again.
At line:1 char:38
+ dir -r F:\ | group extension | select <<<< @{n="Size";e={($_.group
| measure length -sum).sum}},name | sort size -desc | select -first 10
Select-Object : The term 'measure' is not recognized as a cmdlet,
function, operable program, or script file. Verify the term and try
again.
At line:1 char:38

over and over....

Also, could you please explain this section so I learn a little
without just getting the fish?
select @{n="Size";e={($_.group | measure length -sum).sum}},name

Thank you again...


Thanks again...


On Apr 9, 1:11 pm, "Jacques Barathon [MS]"
<jbara...@online.microsoft.com> wrote:
> "Ant" <antgoodl...@gmail.com> wrote in message
>
> news:1176136308.451747.197050@y80g2000hsf.googlegroups.com...
>
> >I have a sample that does extensions by count for my F: drive, but how
> > do I do this by length instead of count?

>
> > get-childitem -r c:\ | group extension | sort-object count -descending
> > | select -first 10

>
> Probably not optimised for a complete drive scan, but basically equivalent
> to your sample:
>
> dir -r c:\ | group extension | select @{n="Size";e={($_.group | measure length -sum).sum}},name | sort size -desc | select -rst 10
>
> Jacques



Old 04-09-2007   #4 (permalink)
Duncan Smith
Guest


 

Re: Group extensions by size


> Thank you, while I am sure this is close, it's throwing this error :
> PS F:\> dir -r F:\ | group extension | select @{n="Size";e={($_.group
> | measure length -sum).sum}},name | sort size -desc | select -first 10
> Select-Object : The term 'measure' is not recognized as a cmdlet,
> function, operable program, or script file. Verify the term and try
> again.
> At line:1 char:38


That's odd, it works here okay on Powershell V1.0. Try expanding
'measure' to 'measure-object'

> Also, could you please explain this section so I learn a little
> without just getting the fish?
> select @{n="Size";e={($_.group | measure length -sum).sum}},name
>
> Thank you again...
>


I can't quite understand the hash-literal in the mid-section either.
I see that n= can be expanded to name=, but any other token generates
an invalid key error, same goes for e=, that must be a short-cut for
something too, enum maybe?

Looks like it's a way of populating the hashtable in-line, but can't
find the relevant documentation.

Thanks,

Duncan.

Old 04-09-2007   #5 (permalink)
Ant
Guest


 

Re: Group extensions by size

Yes, measure-object was the trick.. (And I am using powershell version
1.0 too...) perhaps you have an alias... regardless I'm all set.
Thanks again for your help, now onto deleting linux gzips from my home
drive :-)

PS F:\> dir -r F:\ | group extension | select @{n="Size";e={($_.group
| measure-object length -sum).sum}},name | sort size -desc | select -
first 10


Size Name

---- ----

348529270 .gz

98309149 .exe

47478784 .nsf

47379546 .pdf

36364346 .jar

30728192 .ntf

29310093 .doc

16187033 .dll

10936641 .rtf

10219727 .txt


On Apr 9, 3:12 pm, "Duncan Smith" <DSmith1...@googlemail.com> wrote:
> > Thank you, while I am sure this is close, it's throwing this error :
> > PS F:\> dir -r F:\ | group extension | select @{n="Size";e={($_.group
> > | measure length -sum).sum}},name | sort size -desc | select -first 10
> > Select-Object : The term 'measure' is not recognized as a cmdlet,
> > function, operable program, or script file. Verify the term and try
> > again.
> > At line:1 char:38

>
> That's odd, it works here okay on Powershell V1.0. Try expanding
> 'measure' to 'measure-object'
>
> > Also, could you please explain this section so I learn a little
> > without just getting the fish?
> > select @{n="Size";e={($_.group | measure length -sum).sum}},name

>
> > Thank you again...

>
> I can't quite understand the hash-literal in the mid-section either.
> I see that n= can be expanded to name=, but any other token generates
> an invalid key error, same goes for e=, that must be a short-cut for
> something too, enum maybe?
>
> Looks like it's a way of populating the hashtable in-line, but can't
> find the relevant documentation.
>
> Thanks,
>
> Duncan.



Old 04-09-2007   #6 (permalink)
Jacques Barathon [MS]
Guest


 

Re: Group extensions by size

"Ant" <antgoodlife@gmail.com> wrote in message
news:1176146219.534107.182510@p77g2000hsh.googlegroups.com...
> Yes, measure-object was the trick.. (And I am using powershell version
> 1.0 too...) perhaps you have an alias... regardless I'm all set.
> Thanks again for your help, now onto deleting linux gzips from my home
> drive :-)


Yes, sorry about that. I have a script block in my profile which aliases all
cmdlets having object as their name to their verb only (new-object -> new,
measure-object -> measure, compare-object -> compare, etc).

Re: the in-line hash, I can't tell you where it is documented but I am quite
sure it is somewhere. Others in the PowerShell team may be able to guide you
here. I am aware of those tokens:

* Expression - abbreviated to e.
Contains the code you want to execute, $_ being the current object. This
token is common to all cmdlets that can use such hash. You can only the
expression and nothing else, and then skip the "e=" part of the hash (eg.
select {($_.group | measure-object length -sum).sum}). An example with
another cmdlet than select:
dir | group {"{0}{1}" -f $_.name[0],$_.extension[1]}

* Name - abbreviated to n.
Gives a name to the property you are returning from your expression. I have
used it with select, not sure if it can apply to any other cmdlet.

* Label - abbreviated to l.
Replaces Name in formatting cmdlets.

* Align - abbreviated to a.
Decides of the alignment of text in formatting cmdlets. Can be "left",
"right" or "center". Another example (completely useless, as all great
examples are):
dir | ft @{l="Initials";a="right";e={"{0}{1}" -f
$_.name[0],$_.extension[1]}} -a

There might be other formatting tokens, but I very rarely need them.

Hope that helps,
Jacques

Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Contacts moving from group to group randomly. why? Leon McCalla Live Messenger 0 3 Weeks Ago 11:55 AM
Messenger Group – Enjoy the group chat on your Windows Live Messen Ethan Jone Live Messenger 0 04-27-2008 10:44 PM
Group-Object and getting the full GroupInfo (Group) output. Tolli PowerShell 2 04-08-2008 11:15 AM
Maximum Contact Group Size pennytaffy Live Mail 1 02-02-2008 01:17 AM
Windows Mail Contact Group option GROUP ONLY PECHE RICE Vista mail 0 03-14-2007 01:11 PM








Vistax64.com 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 2005-2008

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 47 48 49 50