Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • yep, it works. Can you explain why? :) as I understand it comma in () means it is actually an array with two sub arrays, right? Commented Aug 22, 2011 at 20:20
  • 9
    @Mishkin - Explanation would be that the -ArgumentList takes in a list/ array of arguments. So when you give -arg $myarr, it is as though you are passing the elements of the array as the arguments. So you have to force powershell to treat it as a single argument which is an array. Commented Aug 22, 2011 at 21:11
  • How would you pass the array and another variable? -arg (,$myarr, $singleValue). For the example, $singleValue = "x" Commented Jun 16, 2017 at 15:27
  • 2
    The problem only happens when try to pass a single array argument, when you pass an array and another argument then you implicitly create another array with the comma. e.g in -arg $array, $value the $array, $value expression is an array which you can see by evaluating it on the command line. ($arr, 5)[0] will print $arr; ($arr, 5)[1] will print 5 Commented Apr 22, 2019 at 7:52
  • 1
    Also true for invoke-command -argumentlist Commented Dec 13, 2024 at 20:01