• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

possible function bug?

K

klumsy@xtra.co.nz

#1
if i make a function

function test
{
$input
}

then do

whatever | test

the results should be and are the same as if i had run whatever,
correct?

likewise if i do the function

function test2
{
begin {}
process {$_ }
end {}
}

that function should effectively do the same thing as test right,
however on a per item basis, EVERYTHING that comes in the pipeline
should go out?

this works in the majority of cases, however if an expession in the
pipeline puts things in the pipeline over multiple expressions, it
fails

i.e
cd "hklm:\system\CurrentControlSet/Control/Session Manager"

(Get-Item .).property | foreach { $_;$( (Get-ItemProperty .).$_ );} |
test2

however actually it works.. its just that i add test2 on, inside C#
code, rather than in script , and in that case it fails, so i don't
know if this is a bug as far as the interfaces are concerned.. however
if i "flatten" it.. all works fine.. i.e

(Get-Item .).property | foreach { $_;$( (Get-ItemProperty .).$_ );} |
% {$_ }
| test2

hmmm...
(b.t.w the contenxt is inside powershell analyzer..
\cd "hklm:\system\CurrentControlSet/Control/Session Manager"

(Get-Item .).property | foreach { $_;$( (Get-ItemProperty .).$_ );}
doesn't show the 2nd lot of things... and its because i am adding a
function on at the last stage of the pipeline that spits out $_ in a
process block..

Karl
(i think i will have confused everybody with this post, well maybe not
the MS guys)
 
J

James Truher

#2
i'm confuseled

The "2nd lot of things" seem to be the result of a sub-expression. have you
tried
$_;$t = gp .;$t.$_
instead?



--
--
James Truher [MSFT]
Windows PowerShell Development
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.

<klumsy@xtra.co.nz> wrote in message
news:1159548814.910445.190010@b28g2000cwb.googlegroups.com...
> if i make a function
>
> function test
> {
> $input
> }
>
> then do
>
> whatever | test
>
> the results should be and are the same as if i had run whatever,
> correct?
>
> likewise if i do the function
>
> function test2
> {
> begin {}
> process {$_ }
> end {}
> }
>
> that function should effectively do the same thing as test right,
> however on a per item basis, EVERYTHING that comes in the pipeline
> should go out?
>
> this works in the majority of cases, however if an expession in the
> pipeline puts things in the pipeline over multiple expressions, it
> fails
>
> i.e
> cd "hklm:\system\CurrentControlSet/Control/Session Manager"
>
> (Get-Item .).property | foreach { $_;$( (Get-ItemProperty .).$_ );} |
> test2
>
> however actually it works.. its just that i add test2 on, inside C#
> code, rather than in script , and in that case it fails, so i don't
> know if this is a bug as far as the interfaces are concerned.. however
> if i "flatten" it.. all works fine.. i.e
>
> (Get-Item .).property | foreach { $_;$( (Get-ItemProperty .).$_ );} |
> % {$_ }
> | test2
>
> hmmm...
> (b.t.w the contenxt is inside powershell analyzer..
> \cd "hklm:\system\CurrentControlSet/Control/Session Manager"
>
> (Get-Item .).property | foreach { $_;$( (Get-ItemProperty .).$_ );}
> doesn't show the 2nd lot of things... and its because i am adding a
> function on at the last stage of the pipeline that spits out $_ in a
> process block..
>
> Karl
> (i think i will have confused everybody with this post, well maybe not
> the MS guys)
>