Windows Vista Forums

Function names and invocation
  1. #1


    Hans Dingemans Guest

    Function names and invocation

    function get-ComRSS
    {
    param($param1)

    $param1
    $param1
    }
    comrss test1

    Why is it that the script above runs to completion without error?

    PS> c:/test
    test1
    test1
    PS>




    I would have expected that 'comrss' is not recognized as a cmdlet, function,
    etc.What's the logic behind this? There must be something special with the
    get verb. Changing comrss into abc throughout the script still does the job.
    Changing get- into something else requires the invocation to spell the
    function name out loud.

    I presume this is by design, but for what reason?

    Cheers,
    Hans

    PS: found a more elaborate sample in Payette's book, pages 408 and 409,
    using this "trick" and could not find easily why the function got invoked.



      My System SpecsSystem Spec

  2. #2


    Jeff Guest

    Re: Function names and invocation

    On Sep 25, 8:32 pm, "Hans Dingemans" <hans_dingem...@xxxxxx>
    wrote:

    > function get-ComRSS
    > {
    > param($param1)
    >
    > $param1
    > $param1}
    >
    > comrss test1
    >
    > Why is it that the script above runs to completion without error?
    >
    > PS> c:/test
    > test1
    > test1
    > PS>
    >
    > I would have expected that 'comrss' is not recognized as a cmdlet, function,
    > etc.What's the logic behind this? There must be something special with the
    > get verb. Changing comrss into abc throughout the script still does the job.
    > Changing get- into something else requires the invocation to spell the
    > function name out loud.
    >
    > I presume this is by design, but for what reason?
    >
    > Cheers,
    > Hans
    >
    > PS: found a more elaborate sample in Payette's book, pages 408 and 409,
    > using this "trick" and could not find easily why the function got invoked.
    You are right; this is by design. I don't know the exact details, but
    during parsing, when a symbol comes up undefined, "get-" is added to
    it to see if a match is found. This just makes more terse use of some
    Cmdlets and functions automatic. You might think "help" is an alias
    for the Cmdlet "Get-Help", but it isn't. You can check this by
    running "Get-Alias help". PowerShell slaps a "get-" on the front when
    a match for "help" isn't found, and you get what you want.

    Jeff


      My System SpecsSystem Spec

  3. #3


    Hans Dingemans Guest

    Re: Function names and invocation

    That must be it, thanx!

    Although this is meant like a feature, to me this is just causing problems
    in the long run.

    PS> location
    Path
    ----
    D:\Books\PowerShell in Action
    PS> command
    Microsoft(R) Windows DOS
    (C)Copyright Microsoft Corp 1990-2001.
    D>

    In the above script, location becomes get-location, whereas command invokes
    good old DOS, not get-command. So when in future an executable 'location' is
    located somewhere in the PATH it gets precedence over get-location! Never
    ever use this FeAtuRe!!


    "Jeff" <jeff.hillman@xxxxxx> wrote in message
    news:1190729975.000834.112680@xxxxxx

    > On Sep 25, 8:32 pm, "Hans Dingemans" <hans_dingem...@xxxxxx>
    > wrote:

    >> function get-ComRSS
    >> {
    >> param($param1)
    >>
    >> $param1
    >> $param1}
    >>
    >> comrss test1
    >>
    >> Why is it that the script above runs to completion without error?
    >>
    >> PS> c:/test
    >> test1
    >> test1
    >> PS>
    >>
    >> I would have expected that 'comrss' is not recognized as a cmdlet,
    >> function,
    >> etc.What's the logic behind this? There must be something special with
    >> the
    >> get verb. Changing comrss into abc throughout the script still does the
    >> job.
    >> Changing get- into something else requires the invocation to spell the
    >> function name out loud.
    >>
    >> I presume this is by design, but for what reason?
    >>
    >> Cheers,
    >> Hans
    >>
    >> PS: found a more elaborate sample in Payette's book, pages 408 and 409,
    >> using this "trick" and could not find easily why the function got
    >> invoked.
    >
    > You are right; this is by design. I don't know the exact details, but
    > during parsing, when a symbol comes up undefined, "get-" is added to
    > it to see if a match is found. This just makes more terse use of some
    > Cmdlets and functions automatic. You might think "help" is an alias
    > for the Cmdlet "Get-Help", but it isn't. You can check this by
    > running "Get-Alias help". PowerShell slaps a "get-" on the front when
    > a match for "help" isn't found, and you get what you want.
    >
    > Jeff
    >


      My System SpecsSystem Spec

  4. #4


    Jeff Guest

    Re: Function names and invocation

    > "Jeff" <jeff.hill...@xxxxxx> wrote in message

    > > You are right; this is by design. I don't know the exact details, but
    > > during parsing, when a symbol comes up undefined, "get-" is added to
    > > it to see if a match is found. This just makes more terse use of some
    > > Cmdlets and functions automatic. You might think "help" is an alias
    > > for the Cmdlet "Get-Help", but it isn't. You can check this by
    > > running "Get-Alias help". PowerShell slaps a "get-" on the front when
    > > a match for "help" isn't found, and you get what you want.
    I just wanted to point out that what I said about "help" is wrong.
    "help" is actually a function defined by PowerShell. I already knew
    that, but I momentarily forgot when I was looking for an example that
    makes use of the default "Get-" verb. Sorry.

    Jeff


      My System SpecsSystem Spec

Function names and invocation problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Method invocation failed B Williams PowerShell 0 31 Mar 2008
Remote invocation of ps commands? Duncan Smith PowerShell 5 05 Oct 2007
Function/Filter names - to hyphenate or not? Keith Hill [MVP] PowerShell 11 04 Dec 2006
COM IDispatch and Powershell invocation =?Utf-8?B?S2Jnbw==?= PowerShell 1 12 Sep 2006
Suggestion: Consider shorter standard names for Alias.Function, and Variable PSDrives Alex K. Angelopoulos [MVP] PowerShell 0 20 Jun 2006