1

How do I read command line arguments in Powershell into an array? Something like

myprogram -file file1 -file file2 -file file3

and then I have an array of

[file1,file2,file3]

Similar question for hash. Thanks.

3

Command line arguments are stored in an array by default. The array is $args[]. If you want named parameters, use param(). If you want to specify multiple arguments for the same parameter, use commas.

Example code:

function myprogram {
    param (
        [string[]]$file
    )
    #Do stuff to $file array here
}

Command line:

myprogram -file file1,file2,file3
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.