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 Tutorial - insert object in pipe

Reply
 
Old 12-03-2006   #1 (permalink)
William Stacey [C# MVP]
Guest


 
 

insert object in pipe

In a filter, is is possible to insert a new object in the pipeline?

filter myfilter
{
# On first call, insert an object in pipe here.
# else, process each object normally.
}

--
William Stacey [C# MVP]




My System SpecsSystem Spec
Old 12-03-2006   #2 (permalink)
Maximilian Hänel
Guest


 
 

Re: insert object in pipe

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
Old 12-04-2006   #3 (permalink)
William Stacey [C# MVP]
Guest


 
 

Re: insert object in pipe

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
Old 12-04-2006   #4 (permalink)
William Stacey [C# MVP]
Guest


 
 

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
Reply

Thread Tools


Similar Threads
Thread Forum
Pipe compare-object results into something useable PowerShell
Pipe a pipe command to a file VB Script
CD Insert/Jewel Case Insert Maker ignored? Vista music pictures video
Testing object arrays using Compare-Object and -contains PowerShell
Adding canonical aliases for Compare-Object, Measure-Object, New-Object PowerShell


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