* Too geeky? Naaah....
568 | Chapter 9: Scripting and Automation
That is, you can??™t easily pipe output to a command that hasn??™t been specifically
designed to receive it. In good ol??™ Unix and DOS, you can pipe anything
to anything. For instance, this PowerShell command:
help | help
which I expected would send a list of Cmdlets generated by help back to
help, which in turn would spit out a detailed explanation of each Cmdlet,
did not work at all. Perhaps this is a silly example, but it sure would??™ve
made my job easier.
What does work well is the passing of filenames from one Cmdlet to
another. Here??™s a sophisticated series of commands that illustrates this:
Get-ChildItem 'H:\MediaCenterPC\My Music' -rec | where { -not $_.
PSIsContainer -and $_.Extension -match "wma|mp3" } | Measure-Object -
property length -sum -min -max -ave
This amalgam of three Cmdlets does the following:
??? Retrieves a list of filenames in the H:\MediaCenterPC\My Music folder
and all its subfolders (thanks to the -rec option), and passes the list to...
??? the where (Where-Object) Cmdlet, which filters out any files that don??™t
have the .wma or .mp3 filename extensions, and then passes the modified
list to...
??? the Measure-Object Cmdlet, which outputs detailed information about
the music files in the list.
And you could keep going like this, including a command that take the output
from Measure-Object to process, store, or display it in some fashion.
Pages:
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791