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 - common pipeline problem i have. (need data from an earler stage, that has been lost)

Reply
 
Old 09-01-2006   #1 (permalink)
Karl Prosser


 
 

common pipeline problem i have. (need data from an earler stage, that has been lost)

I don't have a good example of hand. But in my powershelling i've come
across this quite often.. I have a multistage pipeline. where at various
stages i', processing a subset of the object that was in the first part of
the pipeline, but then later on i also want to reference the object what was
lost..

i.e

ls | select name | ...

loses the FileInfo object , the select destroys it.. Often i want access to
that object again. so often i put a foreach { $backup = $_ ; $_ } in the
pipeline process. so later i can reference the actual object.

this is quite a common issue i have.. the above technique can get quite
messy, and feels like a workaround, and not powershell..

I have noticed that others have had similar problems, and build specific
cmdlets to bridge this logic internally. I.e i build a hacked together
pipeline that would take in an array of fileinfo object, then get the
contents of them, then just get the lines that matches a certian string, but
then match that back with the line number and the filename (thus i needed
access to the fileinfo object later)

somebody here introduced me to the select-string cmdlet, which can take in
FileInfos to the pipeline , do that match, and it outputs a customobject
that contains the Filename, linenumber, match and others info..

However i am looking for a solution that doesn't require writing specific
cmdlets for specific tasks, i'm looking for a powershelly technique that
allows you to elegantly pass more than one thing along the pipeline, i.e
pairs, tupples etc, or more. so that various stages of the pipeline might
process different parts of this.

my thought is having some cmdlets that quickly build a cusomobject adding
more properties to it as it goes.. passing it aloong, and having some other
functions that easily allow you to extract just the part you want in that
stage of the pipeline, then put it back later

so here is some very bad psuedo sort of brainstorming. comments in <>
encapsulate-pipeobject would add whatever's coming through thepipeline as a
new property to the custom object and give it a certian name
foreach-pipeobject is like foreach-object but what it does it takes in this
custom object and applies the scriptblock to just the propertynamed as
inname and stores the results as the property names outname (and if it has
the same name (or outname is omitted) it will store it in the same
property.. it then passes the who psobject on.

dir | encapsulate-pipeobject -name thefile | foreach-pipeobject -inname
thefile -outname contents { get-content } | ...

so at the end above pipeline , you will have an array, of customobjects ,
each with a property "thefile" which will contain the whole fileinfo object
, and "contents" which contains a line of the contents of that file. This
would be a great way to do some of those difficult and tedious things,and
very useful when combined later with the grouping/sorting sort of cmdlets.
I know the idea would need to be refined quite alot, which is why i am
bring it to the many sharp minds here.

-Karl



My System SpecsSystem Spec
Old 09-01-2006   #2 (permalink)
=?Utf-8?B?TWlrZSBCcmlkZ2U=?= bridgecanada _ com>


 
 

RE: common pipeline problem i have. (need data from an earler stage, t

Hi Karl,

If you have a custom-defined attribute that you want to keep track of for
each object, would "add-member" work? Would it work to filter out the
fileinfo members you don't want using "select", and then to use add-member to
add custom data back to each object which can be accessed farther down the
pipeline?

-Mike



"Karl Prosser" wrote:

....
> my thought is having some cmdlets that quickly build a cusomobject adding
> more properties to it as it goes.. passing it aloong, and having some other
> functions that easily allow you to extract just the part you want in that
> stage of the pipeline, then put it back later
>
> so here is some very bad psuedo sort of brainstorming. comments in <>
> encapsulate-pipeobject would add whatever's coming through thepipeline as a
> new property to the custom object and give it a certian name
> foreach-pipeobject is like foreach-object but what it does it takes in this
> custom object and applies the scriptblock to just the propertynamed as
> inname and stores the results as the property names outname (and if it has
> the same name (or outname is omitted) it will store it in the same
> property.. it then passes the who psobject on.
>
> dir | encapsulate-pipeobject -name thefile | foreach-pipeobject -inname
> thefile -outname contents { get-content } | ...
>
> so at the end above pipeline , you will have an array, of customobjects ,
> each with a property "thefile" which will contain the whole fileinfo object
> , and "contents" which contains a line of the contents of that file. This
> would be a great way to do some of those difficult and tedious things,and
> very useful when combined later with the grouping/sorting sort of cmdlets.
> I know the idea would need to be refined quite alot, which is why i am
> bring it to the many sharp minds here.
>
> -Karl
>
>
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Sharing common data properties between multiple users in Vista System Security
Sonic Stage install problem Software
System.Data.Common.DbDataReader and change in type PowerShell
Dual boot XP/Vista sharing common installed applications and data? Vista installation & setup
Common App Data Vista General


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