Windows Vista Forums

possible function bug?

  1. #1


    klumsy@xtra.co.nz Guest

    possible function bug?

    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)


      My System SpecsSystem Spec

  2. #2


    James Truher Guest

    Re: possible function bug?

    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)
    >




      My System SpecsSystem Spec

possible function bug?

Similar Threads
Thread Forum
function more
Consider PS C:> gc function:more param(]$paths) $OutputEncoding = ::OutputEncoding if($paths) { foreach ($file in $paths) { Get-Content...
PowerShell
About the function.
Hi all, I have found on internet two function PowerShell who permit to display a friendly CLI like menu....
PowerShell
function to delete a function
How would a function be written that given a name of a function, would delete that function? I tried with no success function rif { ri...
PowerShell
function not working dispite working outside the function block
I've writen the following function function getusername($a,$b,$c) { $firstletter = $a.substring(0,1) $lastletters = $b.substring(0,3)...
PowerShell
help about function
i confused about how to use fucntion to develop a function. the function calculates the number of files and the total size of files in a folder,...
PowerShell
Function - XML
I've created this function to recieve an XML Document from one of our Web servers. The $Quote.Quote.BestBuyPrice returns the value of...
PowerShell
BUG: Redirecting function contents to a file truncates function lines at the width of the console
In my profile.ps1 file, I have various functions with line widths greater than 80 columns. My console is 80 columns. If I use the following: ...
PowerShell