![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| | |||||||
| |
| 11-10-2007 | #1 (permalink) |
| | 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 Specs |
| 11-10-2007 | #2 (permalink) |
| | Re: Steppable Pipelines in Powershell 2.0 CTP Tao Ma wrote: Quote: > 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. PSH> function step { Quote: Quote: >> begin{write-host "Starting..."} >> process{$_.name} >> end{write-host "Ending..."} >> } >> 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 Specs |
| 11-11-2007 | #3 (permalink) |
| | Re: Steppable Pipelines in Powershell 2.0 CTP Quote: > 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. 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 Specs |
| 11-11-2007 | #4 (permalink) |
| | 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 Specs |
| 11-12-2007 | #5 (permalink) |
| | 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 Quote: > Quote: > > 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 Quote: > > Marco > > -- > Microsoft MVP - Windows PowerShell > http://www.microsoft.com/mvp > > PowerGadgets MVP > http://www.powergadgets.com/mvp > > Blog: > http://marcoshaw.blogspot.com |
| My System Specs |
| 11-12-2007 | #6 (permalink) |
| | Re: Steppable Pipelines in Powershell 2.0 CTP Hi TaoMa, Quote: > 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 ![]() 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 Specs |
| 11-13-2007 | #7 (permalink) |
| | 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 Quote: > Hi TaoMa, > Quote: > > 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 Specs |
| Thread Tools | |
| |
| Similar topics to: Steppable Pipelines in Powershell 2.0 CTP | ||||
| Thread | Forum | |||
| pipelines supported by PowerShell cmdlets | PowerShell | |||
| commenting multiline pipelines | PowerShell | |||
| How do you comment long pipelines | PowerShell | |||
| Colored Text and Pipelines | PowerShell | |||
| ctrl-c affects background pipelines | PowerShell | |||