powershell arguments : PARAM vs ARGS ?


  1.    08 May 2007 #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.    08 May 2007 #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

  3.    08 May 2007 #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

  4.    08 May 2007 #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

  5.    08 May 2007 #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

  6.    09 May 2007 #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

  7.    14 May 2007 #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
how to execute a batch file with arguments from powershell
hi, I have a particular requirement which dictates that i need to execute the batch file from powershell Script. Not only this but the script...
PowerShell
PowerShell param array
Hi, I can't seem to find Microsoft's documentation on how to use the param array to manage input parameters for my PowerShell scripts. I have...
PowerShell
Passing arguments from .BAT to PowerShell script
Hi, I'd like to have a PS script, where I can drag some files in explorer and drop them onto the script (for example, the dropped files are...
PowerShell
Re: how to see arguments with powershell when running winrs
PS > (gwmi win32_process -filter "name='powershell.exe'").commandLine When there is more than one powershell instance running: PS > gwmi...
PowerShell
Calling powershell with spaces in param list
Ok, I have this working on the command line, it just doesn't work when called from within the script. Backgroud I have multiple powershell...
PowerShell
Difference in how PowerShell treats arguments vs CMD
Hi, In CMD, the following commandline: program.exe foo.bar foo -foo.bar results in 3 arguments (as expected). The same commandline in...
PowerShell
Info: Param vs $args
Pros? Cons? Preference?
PowerShell

Our Sites
  • Ten Forums
  • Eight Forums
  • Seven Forums
  • Help Me Bake
  • Site Links
  • Contact Us
  • Privacy and Cookies
  • About Us
    Windows Vista Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

    © Designer Media Ltd
    All times are GMT -5. The time now is 11:50.
    .