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

powershell arguments : PARAM vs ARGS ?

G

Guest

#1
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 Computer

D

Don Jones [MVP]

#2
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 Computer

G

Guest

#3
"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 Computer

K

Keith Hill [MVP]

#4
"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 Computer

M

Marco Shaw

#5
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 Computer

J

J Hugard

#6
"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 Computer

A

Al Dunbar

#7
"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 Computer

Users Who Are Viewing This Thread (Users: 1, Guests: 0)