::::::::: PowerShell :::::::::
Tuesday, January 10, 2006
  /\/\o\/\/ on MSH (Monad): Report MP3 count and size by User from MSH
/\/\o\/\/ on MSH (Monad): Report MP3 count and size by User from MSH

Just a great fun MSH script to play around with... As the topic says, it simply reports MP3 file statistics... on either local machine or on a network computer, etc...

But what is up with those @{expression=...;Name=...} stuff?



If you scroll down a bit, then you will run into two of "select" cmdlets with weird arguments.
Don't worry about it so much, argument is simply an array of a hashtable...

So let's see...
Let's take a look at,

# group them per user 

"`n$Extension Per User"
$Userfiles | group Username | select @{expression={$_.Name};Name="User"},
                               @{expression={($_.group | measure-object).count};Name="Count"},
                               @{expression={($_.group | measure-object -property RoundedSize -sum).sum};Name="MB"}



you will just simply see an array of hashtable object with two keys with matching values

  1. 1st element

    1. expression: {$_.Name}
    2. Name: "User"

  2. 2nd element

    1. expression: {($_.group | measure-object).count}
    2. Name: "Count"

  3. 3rd element

    1. expression: {($_.group | measure-object -property RoundedSize -sum).sum}
    2. Name: "MB"



The value of "Name" key of each Hashobject is used as a header for the output while the values of "expression" evaluate piped input data object(in this case, System.Management.Automation.Commands.GroupInfo object) and spits out the output on the console.
In /\/\o\/\/'s case,

User Count MB
---- ----- --
Usr001 141 998,52
Usr002 547 3746,62


You can see that "User", "Count", and "MB" as headers and the results are simply calculated values from the piped input data.

BTW, to save typing, you don't have to go with something like expression={$_.filename}; name="Filename"(probably for better readability?) since there is no real meaning to name your keys("expression" & "name") that long... For me being such a lazy typist... i was satisfied with the following...


$Userfiles | group Username | select @{e={$_.Name};N="User"},
                               @{e={($_.group | measure-object).count};N="Count"},
                               @{e={($_.group | measure-object -property RoundedSize -sum).sum};N="MB"}


Anyways, it was a fun fun script there /\/\o\/\/~~~

Tags :
 
Comments: Post a Comment



<< Home
Let's get lazy with PowerShell!

Name:
Location: Flushing, NY, United States

Experimenting with a different format of blogs...

Links
ARCHIVES
10/01/2005 - 11/01/2005 / 11/01/2005 - 12/01/2005 / 12/01/2005 - 01/01/2006 / 01/01/2006 - 02/01/2006 / 02/01/2006 - 03/01/2006 / 03/01/2006 - 04/01/2006 / 04/01/2006 - 05/01/2006 / 05/01/2006 - 06/01/2006 / 06/01/2006 - 07/01/2006 / 07/01/2006 - 08/01/2006 / 08/01/2006 - 09/01/2006 / 10/01/2006 - 11/01/2006 / 11/01/2006 - 12/01/2006 /


Powered by Blogger