1.    10 Nov 2007 #1
    Tao Ma Guest

    Steppable Pipelines in Powershell 2.0 CTP


    I notice this new feature:
    Steppable Pipelines

    This feature allows turning a script-block into a steppable pipeline and
    then controlling the sequence of activities by individually calling Begin(),
    Process() and End() on the pipeline.

    I dont know what is the meaning of this. Who can offer an example for me.

    Thanks in advance,

    Best wishes.



      My System SpecsSystem Spec

  2.    10 Nov 2007 #2
    Marco Shaw [MVP] Guest

    Re: Steppable Pipelines in Powershell 2.0 CTP


    Tao Ma wrote:

    > I notice this new feature:
    > Steppable Pipelines
    >
    > This feature allows turning a script-block into a steppable pipeline and
    > then controlling the sequence of activities by individually calling
    > Begin(), Process() and End() on the pipeline.
    Example:

    PSH> function step {

    >> begin{write-host "Starting..."}
    >> process{$_.name}
    >> end{write-host "Ending..."}
    >> }
    >>
    PS> get-childitem . *.ps1|step
    Starting...
    1.ps1
    .... <--removed
    test.ps1
    test1.ps1
    .... <--removed
    Ending...

    In the begin() and end() part, you're not actually doing anything with
    the objects coming in.

    Marco


    --
    Microsoft MVP - Windows PowerShell
    http://www.microsoft.com/mvp

    PowerGadgets MVP
    http://www.powergadgets.com/mvp

    Blog:
    http://marcoshaw.blogspot.com
      My System SpecsSystem Spec

  3.    11 Nov 2007 #3
    Marco Shaw [MVP] Guest

    Re: Steppable Pipelines in Powershell 2.0 CTP



    > Example:
    >
    > PSH> function step {
    > begin{write-host "Starting..."}
    > process{$_.name}
    > end{write-host "Ending..."}
    > }
    >
    > PS> get-childitem . *.ps1|step
    > Starting...
    > 1.ps1
    > ... <--removed
    > test.ps1
    > test1.ps1
    > ... <--removed
    > Ending...
    >
    > In the begin() and end() part, you're not actually doing anything with
    > the objects coming in.
    OK, this is the basic concept behind a steppable pipeline, but isn't
    really the new feature added in the v2 CTP.

    I use a function above to demonstrate, but v1 functions can also do the
    above.

    This may be more of an addition to the new scriptcmdlets feature, the
    more I think about this.

    I can't come up with a practical example right now, but will think about it.

    Marco

    --
    Microsoft MVP - Windows PowerShell
    http://www.microsoft.com/mvp

    PowerGadgets MVP
    http://www.powergadgets.com/mvp

    Blog:
    http://marcoshaw.blogspot.com
      My System SpecsSystem Spec

  4.    11 Nov 2007 #4
    Marco Shaw [MVP] Guest

    Re: Steppable Pipelines in Powershell 2.0 CTP


    This is from the v2 CTP readme below. Another example can be found in
    Sapien's PowerShell TFM *3rd edition* ebook:

    Get-childitem ScriptCmdlet that only shows containers if ØCcontainersonly
    parameter is passed.

    cmdlet Get-ChildItem `
    {
    param(
    [Position(0)] `
    [ValueFromPipeline] `
    [ValueFromPipelineByPropertyName] `
    [System.String[]] `
    $Path,

    [switch] $ContainersOnly
    )
    begin
    {
    $wrappedCmdlet = get-command -type cmdlet Get-ChildItem
    [void] $CommandLineParameters.Remove("ContainersOnly")
    if ($containersonly)
    {
    $sb = {& $wrappedCmdlet @CommandLineParameters | `
    where {$_.PSIsContainer} }
    }
    else
    {
    $sb = { & $wrappedCmdlet @CommandLineParameters }
    }
    $sp = $sb.GetSteppablePipeline()
    $sp.Begin($cmdlet)
    }
    process { $sp.Process($_) }
    end { $sp.End() }
    }
      My System SpecsSystem Spec

  5.    12 Nov 2007 #5
    TaoMa Guest

    Re: Steppable Pipelines in Powershell 2.0 CTP


    Thank you for your help. It's really hard to figure out this new features.
    I wrote a wired code like this:
    1..3 | &{ BEGIN {"head"} PROCESS{$_} END{"tail"} }

    Latterly, I found it can be processed in V1. It seems no one cares this
    feature at all. Maybe this is not a big deal

    Best wishes

    "Marco Shaw [MVP]" <marco.shaw@_NO_SPAM_gmail.com> Š´ČėÓŹ¼ž
    news:OcrtBSFJIHA.3672@xxxxxx

    >

    > > Example:
    > >
    > > PSH> function step {
    > > begin{write-host "Starting..."}
    > > process{$_.name}
    > > end{write-host "Ending..."}
    > > }
    > >
    > > PS> get-childitem . *.ps1|step
    > > Starting...
    > > 1.ps1
    > > ... <--removed
    > > test.ps1
    > > test1.ps1
    > > ... <--removed
    > > Ending...
    > >
    > > In the begin() and end() part, you're not actually doing anything with
    > > the objects coming in.
    >
    > OK, this is the basic concept behind a steppable pipeline, but isn't
    > really the new feature added in the v2 CTP.
    >
    > I use a function above to demonstrate, but v1 functions can also do the
    > above.
    >
    > This may be more of an addition to the new scriptcmdlets feature, the
    > more I think about this.
    >
    > I can't come up with a practical example right now, but will think about
    it.

    >
    > Marco
    >
    > --
    > Microsoft MVP - Windows PowerShell
    > http://www.microsoft.com/mvp
    >
    > PowerGadgets MVP
    > http://www.powergadgets.com/mvp
    >
    > Blog:
    > http://marcoshaw.blogspot.com

      My System SpecsSystem Spec

  6.    12 Nov 2007 #6
    Maximilian Hänel Guest

    Re: Steppable Pipelines in Powershell 2.0 CTP


    Hi TaoMa,

    > Latterly, I found it can be processed in V1. It seems no one cares this
    > feature at all. Maybe this is not a big deal
    I think the key point is that you can convert an arbitry script block to
    a steppable pipline "object". With this kind of object, you can the call
    the begin, process and end method _yourself_ whereas with an ordinary
    scriptblock you can only call the "whole thing" at once.

    Marco already posted an example:

    $sb = {& $wrappedCmdlet @CommandLineParameters | `
    where {$_.PSIsContainer} }
    $sp = $sb.GetSteppablePipeline()

    now you can call begin, process and end on the $sp variable - the
    steppable pipeline.

    $sp.Begin()
    $sp.Process('bla') # call process as often as you want - step by step!
    $sp.Process('foo')
    #...
    $sp.End() #end of story..

    Without converting the scriptblock to a steppable pipeline you must call
    it as "one big thing":

    .. $sp # run the whole script/pipeline/whatever

    This is only a guess, however...

    cu

    Max
      My System SpecsSystem Spec

  7.    13 Nov 2007 #7
    TaoMa Guest

    Re: Steppable Pipelines in Powershell 2.0 CTP


    I'm too careless to read Marco Shaw's post. Thank you for your help.

    It's all my fault.

    Best wishes!

    "Maximilian Hänel" <ngSpam@xxxxxx> ????
    news:%23s0bMfSJIHA.4228@xxxxxx

    > Hi TaoMa,
    >

    > > Latterly, I found it can be processed in V1. It seems no one cares this
    > > feature at all. Maybe this is not a big deal
    >
    > I think the key point is that you can convert an arbitry script block to
    > a steppable pipline "object". With this kind of object, you can the call
    > the begin, process and end method _yourself_ whereas with an ordinary
    > scriptblock you can only call the "whole thing" at once.
    >
    > Marco already posted an example:
    >
    > $sb = {& $wrappedCmdlet @CommandLineParameters | `
    > where {$_.PSIsContainer} }
    > $sp = $sb.GetSteppablePipeline()
    >
    > now you can call begin, process and end on the $sp variable - the
    > steppable pipeline.
    >
    > $sp.Begin()
    > $sp.Process('bla') # call process as often as you want - step by step!
    > $sp.Process('foo')
    > #...
    > $sp.End() #end of story..
    >
    > Without converting the scriptblock to a steppable pipeline you must call
    > it as "one big thing":
    >
    > . $sp # run the whole script/pipeline/whatever
    >
    > This is only a guess, however...
    >
    > cu
    >
    > Max

      My System SpecsSystem Spec


Similar Threads
Thread Forum
pipelines supported by PowerShell cmdlets
From: http://technet.microsoft.com/en-us/library/dd315282.aspx <# Description The Write-Output cmdlet sends the specified object down the...
PowerShell
commenting multiline pipelines
Why doesn't this work? "hello" | # get some data % { $_ } # use it it generates the error: An empty pipe element is not...
PowerShell
How do you comment long pipelines
I have this function. It will probably wrap horribly but I hope you get the idea. How can I comment it? Nearly every spot I've tried to put any...
PowerShell
Colored Text and Pipelines
All, I am writing a script that will parse log files for remote backup jobs. As it stands right now, if the script is invoked with an -html...
PowerShell
Automatic PowerShell Error Parsing in PowerShell Analyzer and PowerShellPlus
PowerShell Analyzer and PowerShell Plus now have automatic PowerShell syntax parsing of PowerShell Script. see a screenshot and read more about...
PowerShell
PowerShell Leaders Join Forces and offer a pre-release version of PowerShell for 50% off the retail value
Shell Tools officially announced that Dr. Tobias Weltner (MVP); author of the award winning "System Scripter" has joined the company. Weltner...
PowerShell
ctrl-c affects background pipelines
Ctrl-C seems to be processed by background pipelines as well as the foreground one. This is frustrating and unexpected. There's already the Stop()...
PowerShell

Our Sites
  • Ten Forums
  • Eight Forums
  • Seven Forums
  • PC Help Forum
  • Help Me Bake
  • Site Links
  • Contact Us
  • Privacy and Cookies
  • About Us
    Windows Vista Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

    © Designer Media Ltd
    All times are GMT -5. The time now is 07:20.
    .