How to receive two passed cmdline parameters and access them inside a Powershell script?

Assume I have have a powershell script myscript.ps1 (on Windows 10).

Now I want to call this script (from command line) and pass two parameters (separated by blanks) e.g.

myscript.ps1 “D:\tools\input data.txt” 65656

The parameters may or may not enclosed in double quotes (as above).

How can I access these passed parameters from inside the script?
Say I want to echo/output them (=the values) simply on command line.

It would be nice to get a sample script.

Thank you

What’s valid for function is valid for scripts as well … you simply provide a param block in your script and specify the parameters you want to work with.

I’d recommend using named parameters instead of positional ones. This way you dont have to remember the order if you have more than just 2 parameters for example. :wink:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.