Windows Vista Forums

powershell arguments : PARAM vs ARGS ?

  1. #1


    Guest

    powershell arguments : PARAM vs ARGS ?

    Hi, i've got a question again :
    after my multiple researchs on the internet, i still don't understand the
    difference between the call of a function with



    function toto($argument1, $argument2, ...)
    {
    ...
    }



    or with


    function toto
    {
    param ( [string] $arguments1, [string] $arguments2)
    ...
    }


    Could someone explain it to me ?

    Thanx
    bye
    Nico



      My System SpecsSystem Spec

  2.   


  3. #2


    Don Jones [MVP] Guest

    Re: powershell arguments : PARAM vs ARGS ?

    No difference. Personal preference in style.

    --
    Don Jones
    Windows PowerShell MVP
    Founder: www.ScriptingAnswers.com
    Co-Author: "Windows PowerShell: TFM"

    <Nicopil@mi> wrote in message news:4640eca0$0$11178$426a74cc@news.free.fr...
    > Hi, i've got a question again :
    > after my multiple researchs on the internet, i still don't understand the
    > difference between the call of a function with
    >
    >
    >
    > function toto($argument1, $argument2, ...)
    > {
    > ...
    > }
    >
    >
    >
    > or with
    >
    >
    > function toto
    > {
    > param ( [string] $arguments1, [string] $arguments2)
    > ...
    > }
    >
    >
    > Could someone explain it to me ?
    >
    > Thanx
    > bye
    > Nico
    >
    >



      My System SpecsSystem Spec

  4. #3


    Guest

    Re: powershell arguments : PARAM vs ARGS ?


    "Don Jones [MVP]" <don@sapien.com> a écrit dans le message de news:
    AFD49370-1BE9-4691-BC13-4B36391BE5F0@microsoft.com...
    > No difference. Personal preference in style.
    >
    > --
    > Don Jones
    > Windows PowerShell MVP
    > Founder: www.ScriptingAnswers.com
    > Co-Author: "Windows PowerShell: TFM"
    >
    > <Nicopil@mi> wrote in message
    > news:4640eca0$0$11178$426a74cc@news.free.fr...
    >> Hi, i've got a question again :
    >> after my multiple researchs on the internet, i still don't understand the
    >> difference between the call of a function with
    >>
    >>
    >>
    >> function toto($argument1, $argument2, ...)
    >> {
    >> ...
    >> }
    >>
    >>
    >>
    >> or with
    >>
    >>
    >> function toto
    >> {
    >> param ( [string] $arguments1, [string] $arguments2)
    >> ...
    >> }
    >>
    >>
    >> Could someone explain it to me ?
    >>
    >> Thanx
    >> bye
    >> Nico
    >>
    >>

    >


    oki
    thx
    bye
    Nico



      My System SpecsSystem Spec

  5. #4


    Keith Hill [MVP] Guest

    Re: powershell arguments : PARAM vs ARGS ?

    "Don Jones [MVP]" <don@sapien.com> wrote in message
    news:AFD49370-1BE9-4691-BC13-4B36391BE5F0@microsoft.com...
    > No difference. Personal preference in style.
    >


    Although the param() approach is required to define the parameters for a
    script file. The param statement also needs to be the first line of script
    in the file IIRC.

    --
    Keith



      My System SpecsSystem Spec

  6. #5


    Marco Shaw Guest

    Re: powershell arguments : PARAM vs ARGS ?

    Don Jones [MVP] wrote:
    > No difference. Personal preference in style.
    >


    But he also sets the type in the 2nd example, which he's not doing in
    the first.

    Marco

      My System SpecsSystem Spec

  7. #6


    J Hugard Guest

    Re: powershell arguments : PARAM vs ARGS ?

    "Marco Shaw" wrote:

    > Don Jones [MVP] wrote:
    > > No difference. Personal preference in style.
    > >

    >
    > But he also sets the type in the 2nd example, which he's not doing in
    > the first.



    Nico:

    Just so you know, you can do this too:

    function toto([string]$argument1, [string]$argument2, ...)
    {
    ...
    }



      My System SpecsSystem Spec

  8. #7


    Al Dunbar Guest

    Re: powershell arguments : PARAM vs ARGS ?


    "J Hugard" <SpamSpamEggsAndSpam@nospam.nospam> wrote in message
    news:1098F215-E902-4529-A44D-2F8EEE170F33@microsoft.com...
    > "Marco Shaw" wrote:
    >
    >> Don Jones [MVP] wrote:
    >> > No difference. Personal preference in style.
    >> >

    >>
    >> But he also sets the type in the 2nd example, which he's not doing in
    >> the first.

    >
    >
    > Nico:
    >
    > Just so you know, you can do this too:
    >
    > function toto([string]$argument1, [string]$argument2, ...)
    > {
    > ...
    > }


    Can you also define optional parameters this way too?

    /Al



      My System SpecsSystem Spec


powershell arguments : PARAM vs ARGS ?
Similar Threads
Thread Forum
PowerShell param array PowerShell
Passing arguments from .BAT to PowerShell script PowerShell
Calling powershell with spaces in param list PowerShell
Difference in how PowerShell treats arguments vs CMD PowerShell
Info: Param vs $args PowerShell