# Passing named arguments to a script using -Argumentlist

**URL:** <https://forums.powershell.org/t/passing-named-arguments-to-a-script-using-argumentlist/2613>\
**Category:** PowerShell Help\
**Created:** [May 24, 2014, 5:27pm UTC](https://forums.powershell.org/t/passing-named-arguments-to-a-script-using-argumentlist/2613 "2014-05-24T17:27:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tulasi-moka](https://avatars.discourse-cdn.com/v4/letter/t/bbce88/32.png) [@tulasi-moka](https://forums.powershell.org/u/tulasi-moka)\
**Post date:** [May 24, 2014, 5:27pm UTC](https://forums.powershell.org/t/passing-named-arguments-to-a-script-using-argumentlist/2613/1 "2014-05-24T17:27:17Z")

</div>

Hi

I want to execute a script on a remote machine using Invoke-command. My script file accepts name arguments. Can someone help me how to use the Invoke-command with -Argumentlist and named parameters.

Invoke-command -computername localhost -filepath .\sample.ps1 -argumentlist (Need this part)

My script file accepts two parameters: .\sample.ps1 -foo “abc” -bar “xyz”

Regards,  
Tulasi Krishna.

---

<div class="post-metadata">

**Author:** ![daniel-krebs](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/daniel-krebs/32/484_2.png) [@daniel-krebs](https://forums.powershell.org/u/daniel-krebs)\
**Post date:** [May 24, 2014, 5:41pm UTC](https://forums.powershell.org/t/passing-named-arguments-to-a-script-using-argumentlist/2613/2 "2014-05-24T17:41:48Z")

</div>

Please check out “Example 11” in the help of Invoke-Command.

Get-Help Invoke-Command -Examples

It explains how this scenario works and shows the ArgumentList parameter in action.

Regards,  
Daniel

---

<div class="post-metadata">

**Author:** ![tulasi-moka](https://avatars.discourse-cdn.com/v4/letter/t/bbce88/32.png) [@tulasi-moka](https://forums.powershell.org/u/tulasi-moka)\
**Post date:** [May 24, 2014, 6:33pm UTC](https://forums.powershell.org/t/passing-named-arguments-to-a-script-using-argumentlist/2613/3 "2014-05-24T18:33:41Z")

</div>

Hi Daniel,

The example shows only normal parameters. But my script takes named parameters. How to pass named parameters there?

If I try like the below, I get an error

Invoke-command -ComputerName localhost -FilePath C:\scripts\Simple1.ps1 -ArgumentList -foo “C:\Temp\a.txt” -bar “C:\Temp\b.txt”

Error:

Invoke-Command : A positional parameter cannot be found that accepts argument ‘C:\Temp\a.txt’.  
At line:1 char:15

- Invoke-Command \<\<\<\< -ComputerName localhost -FilePath C:\scripts\Simple1.ps1 -ArgumentList -foo C:\Temp\a.txt -bar C  
:\Temp\b.txt
  - CategoryInfo : InvalidArgument: (🙂 [Invoke-Command], ParameterBindingException
  - FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeCommandCommand

Regards,  
Tulasi Krishna.

---

<div class="post-metadata">

**Author:** ![daniel-krebs](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/daniel-krebs/32/484_2.png) [@daniel-krebs](https://forums.powershell.org/u/daniel-krebs)\
**Post date:** [May 24, 2014, 10:07pm UTC](https://forums.powershell.org/t/passing-named-arguments-to-a-script-using-argumentlist/2613/4 "2014-05-24T22:07:20Z")

</div>

Sorry I didn’t read that you want to pass named parameter earlier this morning. Unfortunately Invoke-Command does not support this out of the box. I found a thread on StackOverflow with possible workarounds.

[http://stackoverflow.com/questions/4225748/how-do-i-pass-named-parameters-with-invoke-command](http://stackoverflow.com/questions/4225748/how-do-i-pass-named-parameters-with-invoke-command)

Regards,  
Daniel

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:52pm UTC](https://forums.powershell.org/t/passing-named-arguments-to-a-script-using-argumentlist/2613/5 "2024-05-16T20:52:03Z")

</div>


