PowerShell Description

PowerShell Description

  • Comments 1

Following Slashdot's review of Bruce's book (PowerShell in Action ), a ton of people chimed in with comments. One of the most interesting as this one from nacturation:

  • Imagine someone gave you some library code, but to use the code you couldn't pass in variables, objects, or whatever. Each function in the library takes one input -- a string. The return from the functions are also one output -- a string. You need to convert this to/from any meaningful format in order for you to use it. That is bash.

    Now imagine the same thing, but instead of passing in strings you could pass in/out native data types, full objects, other methods, etc. That's PowerShell.
     

Well said.

Jeffrey Snover [MSFT]
Windows Management Partner Architect
Visit the Windows PowerShell Team blog at: http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at: http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx

Leave a Comment
  • Please add 4 and 5 and type the answer here:
  • Post
  • The comments also contained the usual selection of "On *nix I can do X"

    [code]

    du -x / | sort -nr > mem.txt &

    [/code]

    was the first I came across and of course I fell into the trap of thinking about how I'd do it in PSH. I came up with:

    [code]

    function global:Measure-Directory

    {

     param (

       [string]$Path = (write-error `

         "Usage: Measure-Directory [-Path] path [-Recurse]"),

       [switch]$Recurse = $false

     )

     process {

       gci $Path -Rec:$Recurse |

       ? { $_.psiscontainer } |

       % { $dir=$_; gci $_.fullname |

         ? { -not $_.psiscontainer } |

         measure -sum -average -minimum -maximum length |

         % {

           add-member -name Length -value $_.Sum -membertype NoteProperty -pass -inp $dir |

           add-member -name Count -value $_.Count -membertype NoteProperty -pass |

           add-member -name Average -value $_.Average -membertype NoteProperty -pass |

           add-member -name Minimum -value $_.Minimum -membertype NoteProperty -pass |

           add-member -name Maximum -value $_.Maximum -membertype NoteProperty -pass

         }

       }

     }

    }

    set-alias du Measure-Directory

    [/code]

    that would allow me to issue:

    [code]du -r / |sort length -desc > mem.txt[/code]

    But it would also allow me to issue:

    [code]du / -rec |? {$_.count -gt 10}|? {$_.LastWriteTime -gt "2007-01"} |sort length |ft Length,Count,Minimum,Maximum,Average,LastWriteTime,fullname -auto -wrap[/code]

Page 1 of 1 (1 items)