none
Multiple Actions from pipeline output RRS feed

  • Question

  • Hi All,

    First of all, I'm sorry if this doesn't make complete sense, ill try and explain it as best as possible. Is it possible to use the output of a pipeline for multiple actions?

    e.g. Get-ChildItem | DOTHIS & DOTHAT & DOTHIS

    e.g. Get-ChildItem | Remove-Item & Out-file C:\Blar.txt & measure (NOTE, this is just an example, im not looking for help on how to remove files, log them to a file and Count them)

    I know I could use Get-ChildItem | % {Blar ; Blar ; Blar} but as in the above example I may want to use the full output not foreach object (as in measure) (Yes again I could do a $Blar++ to get the total number of objects but again this is just an example replace measure with any number of other possible actions)

    I also I know I could use a full foreach loop i.e.

    Foreach ($Item in Get-Childitem) {

    Remove-item $Item

    $Item | Out-file -append C:\Blar 

    $Count += $Item}

    I could also use

    $TEST = Get-ChildItem

    $TEST.Count

    $TEST | Out-file -append C:\BLAR.txt

    $TEST | Remove-Item

    Problem here is I like the pipeline as it actions each object as it gets it as opposed to $TEST = Get-ChildItem would wait until all objects are stored in the variable.

    So again, my question is can I perform multiple actions from the pipeline, NOT how do I solve the specific examples I have provided above.

    Monday, August 3, 2015 2:24 AM

Answers

  • jrv,

    Thank you very much for taking the time out to respond (even if it was utterly useless).

    It would bebetter if you could ask a specific question.

    Also look at:

    Help tee-object -full

    Overall your post is very ambiguous.  What could you be trying to refer to.  Any amount of code can be run in a pipeline.  YOu canuse constructs like Where-Object and ForEach-Oblect to include block of code that perform all kinds of operation.

    Again; until you learn the basics of PowerShell you will not find it easy to understand how these things are used.  Start with any of the good tutorials.


    \_(ツ)_/

    • Marked as answer by TheJMan69 Monday, August 3, 2015 4:07 AM
    Monday, August 3, 2015 3:36 AM

All replies

  • You can do many things in the pipeline.

    Just add them up.

    Help ForEach-Obiect -full

    The first thing is to learn PowerShell.  Once you have the basics all of these questions will have obvious answers.


    \_(ツ)_/

    Monday, August 3, 2015 3:11 AM
  • jrv,

    Thank you very much for taking the time out to respond (even if it was utterly useless).

    Monday, August 3, 2015 3:26 AM
  • jrv,

    Thank you very much for taking the time out to respond (even if it was utterly useless).

    It would bebetter if you could ask a specific question.

    Also look at:

    Help tee-object -full

    Overall your post is very ambiguous.  What could you be trying to refer to.  Any amount of code can be run in a pipeline.  YOu canuse constructs like Where-Object and ForEach-Oblect to include block of code that perform all kinds of operation.

    Again; until you learn the basics of PowerShell you will not find it easy to understand how these things are used.  Start with any of the good tutorials.


    \_(ツ)_/

    • Marked as answer by TheJMan69 Monday, August 3, 2015 4:07 AM
    Monday, August 3, 2015 3:36 AM
  • Simple example of multiple actins in a pipeline:

     get-process | where name -eq svchost|select id,handles,processname|convertto-csv

    Run this and analyze how it works.  You may need to look up things with your search engine or in the help but once you understand what each of the parts do and how they do it you will better understand how the pipeline works.

    PowerShell and the pipeline work with objects.  Perhaps that is the first thing to become versed in.

    What are objects?  Why?  How does the pipeline use objects.


    \_(ツ)_/

    • Marked as answer by TheJMan69 Monday, August 3, 2015 4:07 AM
    • Unmarked as answer by TheJMan69 Monday, August 3, 2015 4:07 AM
    Monday, August 3, 2015 3:53 AM
  • Tee-Object might be the winner.....

    As I (perhaps clumsily) tried to say I don't have a specific question/problem, other then "Is it possible to use the output of a pipeline for multiple actions"?

    Again I know there are at least three other ways of achieving the same result by NOT using the pipeline I had my reasons for wanting to use pipe.

    Using the example in which I use the pipeline to perform 3 actions on the output of Get-Childitem, this works;

    Get-ChildItem | Tee-Object -Variable BLAR | Measure ; $BLAR.Fullname ; $BLAR | Out-file -append C:\temp\BLAR.txt

    And I'm sure this is true of a number of other examples I could come up with. Thank you.

    Monday, August 3, 2015 4:07 AM
  • ...

    I had my reasons for wanting to use pipe.

    ...

    And am I correct that you want to enhance overall execution time by using the pipeline?
    Monday, August 3, 2015 6:59 PM