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

**URL:** <https://forums.powershell.org/t/how-to-receive-two-passed-cmdline-parameters-and-access-them-inside-a-powershell-script/23595>\
**Category:** PowerShell Help\
**Created:** [February 17, 2024, 11:05am UTC](https://forums.powershell.org/t/how-to-receive-two-passed-cmdline-parameters-and-access-them-inside-a-powershell-script/23595 "2024-02-17T11:05:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pstein](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@pstein](https://forums.powershell.org/u/pstein)\
**Post date:** [February 17, 2024, 11:05am UTC](https://forums.powershell.org/t/how-to-receive-two-passed-cmdline-parameters-and-access-them-inside-a-powershell-script/23595/1 "2024-02-17T11:05:12Z")

</div>

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  
Peter

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [February 17, 2024, 11:57am UTC](https://forums.powershell.org/t/how-to-receive-two-passed-cmdline-parameters-and-access-them-inside-a-powershell-script/23595/2 "2024-02-17T11:57:30Z")

</div>

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.

> **[about Functions Advanced Parameters - PowerShell](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_functions_advanced_parameters?view=powershell-7.4)**
>
> Explains how to add parameters to advanced functions.

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. 😉

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [March 18, 2024, 11:57am UTC](https://forums.powershell.org/t/how-to-receive-two-passed-cmdline-parameters-and-access-them-inside-a-powershell-script/23595/3 "2024-03-18T11:57:38Z")

</div>

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