Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.


Go Back   Vista Forums > Misc Newsgroups > PowerShell

RB

Vista - powershell arguments : PARAM vs ARGS ?

Reply
 
05-08-2007   #1


 
 

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
05-08-2007   #2
Don Jones [MVP]


 
 

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


 
 

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
05-08-2007   #4
Keith Hill [MVP]


 
 

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
05-08-2007   #5
Marco Shaw


 
 

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
05-09-2007   #6
J Hugard


 
 

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
05-14-2007   #7
Al Dunbar


 
 

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
Reply

RB


Thread Tools


Similar Threads for: powershell arguments : PARAM vs ARGS ?
Thread Forum
PowerShell param array PowerShell
Re: how to see arguments with powershell when running winrs PowerShell
Calling powershell with spaces in param list PowerShell
Difference in how PowerShell treats arguments vs CMD PowerShell
Info: Param vs $args PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd