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

Vista - passing arguments

Reply
 
Old 12-19-2006   #1 (permalink)
VB


 
 

passing arguments

PS C:\Documents and Settings\temp> $arg
aaaa
bbbb
cccc
PS C:\Documents and Settings\temp> $(& .\arg.ps1 $(foreach($a in $arg) {
$a} ) )
arg1 = aaaa bbbb cccc
arg2 =

Currently it is passing all values in array $arg to the first argument
(arg1) of args.ps1 - I would like to pass $arg values to all arguments
incrementaly- what code that will be?

ex:
arg1 = aaaa
arg2 = bbbb

VB



My System SpecsSystem Spec
Old 12-19-2006   #2 (permalink)
Jacques Barathon [MS]


 
 

Re: passing arguments

"VB" <truncho@yahoo.com> wrote in message
news:Odncum1IHHA.1276@TK2MSFTNGP04.phx.gbl...
> PS C:\Documents and Settings\temp> $arg
> aaaa
> bbbb
> cccc
> PS C:\Documents and Settings\temp> $(& .\arg.ps1 $(foreach($a in $arg) {
> $a} ) )
> arg1 = aaaa bbbb cccc
> arg2 =
>
> Currently it is passing all values in array $arg to the first argument
> (arg1) of args.ps1 - I would like to pass $arg values to all arguments
> incrementaly- what code that will be?
>
> ex:
> arg1 = aaaa
> arg2 = bbbb


A way to address this is to declare the array explicitly in the param
section of your script. Given the following script:

--- words.ps1
param ([array]$words)
$word1,$word2,$word3 = $words
"`$word1 = $word1"
"`$word2 = $word2"
"`$word3 = $word3"

You can then do this:

PS> $arg = "hello","world","welcome","onboard"
PS> .\words $arg
$word1 = hello
$word2 = world
$word3 = welcome onboard

Hope that helps,
Jacques

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Passing Argument Names as arguments PowerShell
Passing arguments to external command through PS PowerShell
Need help - passing string arguments with quotes PowerShell
Passing arguments into scripts? PowerShell
Passing arguments to a function 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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46