View Single Post
Old 12-04-2006   #4 (permalink)
William Stacey [C# MVP]


 
 

Re: insert object in pipe

And you don't even need the flag. Just send in the begin block. I remember
talking/wanting this cmdlet-like feature in scripts a year ago. They did not
think it would get in v1. Glad it did along with parms. Nice.

filter myfilter
{
begin
{
"Begin" # insert string.
}
process
{
$_ # pass along pipe object.
}
end
{
"End" # pass string.
}
}

PS C:\> "a","b" | myfilter
Begin
a
b
End

--
William Stacey [C# MVP]

"William Stacey [C# MVP]" <william.stacey@gmail.com> wrote in message
news:O$aE%23o2FHHA.320@TK2MSFTNGP06.phx.gbl...
|o man, that is cool. Thank you.
|
| --
| William Stacey [C# MVP]
|
| "Maximilian Hänel" <ngSpam@smjh.de> wrote in message
| news:Or5Kg71FHHA.536@TK2MSFTNGP02.phx.gbl...
|| Hi William
||
|| > In a filter, is is possible to insert a new object in the pipeline?
||
|| Yes, that's possible. Depending of what's your goal you could place yor
|| new object in the begin section.
||
|| filter myfilter
|| {
|| begin
|| {
|| $firstcall=$true
|| }
|| process
|| {
|| if($firstcall)
|| {
|| $firstcall=$false
|| # On first call, insert an object in pipe here.
|| get-date
|| # uncomment next line to insert the current
|| # pipline object, too
|| # $_
|| }
|| else
|| {
|| # else, process each object normally.
|| $_
|| }
|| }
|| end
|| {
|| # The end
|| }
|| }
||
|| hth
||
|| Max
|
|


My System SpecsSystem Spec