How to pass a list of files as parameters to a powershell script

Question:

How does one pass a list of files as parameters to a Powershell script?

When I try to run it

it prints

but I expected something similar to

Answer:

The two solutions presented thusfar (even though one is accepted and both have upvotes) do not really provide an adequate solution to the question–they both make you jump through hoops. The question as posed stated that by just putting *.dat on the commmand line, how can one make the underlying code treat it like you would expect. That is, how to make the code simply do the right thing. With other shells and other cmdlets, all you do is *.dat, not like this:


(OK, I exaggerate to make a point:-) But there is an easy way to just do the right thing–check if wildcards are used and then just expand them:

Source:

How to pass a list of files as parameters to a powershell script by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply