arrays - Passing script parameters to a function in Powershell -


my script calls function needs parameters calling of scripts:

function new( $args ) {   if( $args.length -lt 8 )   {     write-host "parameter missing, requires 8 parameters. aborting."!     write-host $args.length     break   } }  switch ($args[0]) {   '--test' { }   '--new' { new $args }   default  { } } 

when call it, args array not handed on new function:

ps q:\mles\etl-i_test> .\iprog.ps1 --new 1 2 3 4 5 6 7 parameter missing, requires 8 parameters. aborting. ! 0 

how pass array function in powershell? or specifically, $args array? shouldn't scope $args array global?

modify function below:

function new { param([string[]] $paramargs)    if( $paramargs.length -lt 8 )   {     write-host "parameter missing, requires 8 parameters. aborting."!     write-host $paramargs.length     break   } }  switch ($args[0]) {   '--test' { }   '--new' { new $args }   default  { } } 

this avoid ambiguity of variable $arg command line , parameter $arg (changed $paramarg).


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -