Invoke-Command returns only a single object when called using ScriptBlock and ArgumentListhow to edit a file in powershell remoting session (powershell)Using Powershell's Invoke-Command to call a batch file with argumentsNew-PSSession in Job blocks JobInvoke-WmiMethod not working with powershell pssession (invoke-command)How can my local PowerShell script call a remote PowerShell script?Issues with Powershell Invoke-CommandInvoke-Command and Enter-PSsession - DiffrencesFunctions tabular output changing on some remote computersHow to correctly pass a string array as a parameter in a PowerShell 4.0 Invoke-Command -ScriptBlockUsing invoke-command with register-scheduledjob and passing parameters: nested -argumentlist?

Can somebody explain Brexit in a few child-proof sentences?

Divine apple island

Folder comparison

Have I saved too much for retirement so far?

Varistor? Purpose and principle

How should I respond when I lied about my education and the company finds out through background check?

Should I stop contributing to retirement accounts?

How do you respond to a colleague from another team when they're wrongly expecting that you'll help them?

How can "mimic phobia" be cured or prevented?

Can a significant change in incentives void an employment contract?

Query about absorption line spectra

What does this horizontal bar at the first measure mean?

Translation of Scottish 16th century church stained glass

Drawing ramified coverings with tikz

List of people who lose a child in תנ"ך

Reply 'no position' while the job posting is still there

Why did the EU agree to delay the Brexit deadline?

Some numbers are more equivalent than others

Can I use my Chinese passport to enter China after I acquired another citizenship?

Is there a conventional notation or name for the slip angle?

Visiting the UK as unmarried couple

Difference between -| and |- in TikZ

Fuse symbol on toroidal transformer

A social experiment. What is the worst that can happen?



Invoke-Command returns only a single object when called using ScriptBlock and ArgumentList


how to edit a file in powershell remoting session (powershell)Using Powershell's Invoke-Command to call a batch file with argumentsNew-PSSession in Job blocks JobInvoke-WmiMethod not working with powershell pssession (invoke-command)How can my local PowerShell script call a remote PowerShell script?Issues with Powershell Invoke-CommandInvoke-Command and Enter-PSsession - DiffrencesFunctions tabular output changing on some remote computersHow to correctly pass a string array as a parameter in a PowerShell 4.0 Invoke-Command -ScriptBlockUsing invoke-command with register-scheduledjob and passing parameters: nested -argumentlist?













1















When code is invoked though Invoke-Command using the -ScriptBlock, -ArgumentList and -Computer parameters, only a single item is returned from each call to the servers.



Two examples can be found below highlighting the problem.



$s = New-PSSession -ComputerName Machine01, Machine02

# when called, this block only retuns a single item from the script block
# notice that the array variable is being used
Invoke-Command -Session $s -ScriptBlock % select @name='__id'; ex=$i , DisplayName

-ArgumentList 1,2,3

write-host "`r`n======================================`r`n"

# when called, this block retuns all items from the script block
# notice that the call is the same but instead of using the array variable we use a local array
Invoke-Command -Session $s -ScriptBlock % select @name='__id'; ex=$i , DisplayName

-ArgumentList 1,2,3

$s | Remove-PSSession


Can anyone explain to me what i am doing wrong? I cant be the only person caught out by this.










share|improve this question




























    1















    When code is invoked though Invoke-Command using the -ScriptBlock, -ArgumentList and -Computer parameters, only a single item is returned from each call to the servers.



    Two examples can be found below highlighting the problem.



    $s = New-PSSession -ComputerName Machine01, Machine02

    # when called, this block only retuns a single item from the script block
    # notice that the array variable is being used
    Invoke-Command -Session $s -ScriptBlock % select @name='__id'; ex=$i , DisplayName

    -ArgumentList 1,2,3

    write-host "`r`n======================================`r`n"

    # when called, this block retuns all items from the script block
    # notice that the call is the same but instead of using the array variable we use a local array
    Invoke-Command -Session $s -ScriptBlock % select @name='__id'; ex=$i , DisplayName

    -ArgumentList 1,2,3

    $s | Remove-PSSession


    Can anyone explain to me what i am doing wrong? I cant be the only person caught out by this.










    share|improve this question


























      1












      1








      1








      When code is invoked though Invoke-Command using the -ScriptBlock, -ArgumentList and -Computer parameters, only a single item is returned from each call to the servers.



      Two examples can be found below highlighting the problem.



      $s = New-PSSession -ComputerName Machine01, Machine02

      # when called, this block only retuns a single item from the script block
      # notice that the array variable is being used
      Invoke-Command -Session $s -ScriptBlock % select @name='__id'; ex=$i , DisplayName

      -ArgumentList 1,2,3

      write-host "`r`n======================================`r`n"

      # when called, this block retuns all items from the script block
      # notice that the call is the same but instead of using the array variable we use a local array
      Invoke-Command -Session $s -ScriptBlock % select @name='__id'; ex=$i , DisplayName

      -ArgumentList 1,2,3

      $s | Remove-PSSession


      Can anyone explain to me what i am doing wrong? I cant be the only person caught out by this.










      share|improve this question
















      When code is invoked though Invoke-Command using the -ScriptBlock, -ArgumentList and -Computer parameters, only a single item is returned from each call to the servers.



      Two examples can be found below highlighting the problem.



      $s = New-PSSession -ComputerName Machine01, Machine02

      # when called, this block only retuns a single item from the script block
      # notice that the array variable is being used
      Invoke-Command -Session $s -ScriptBlock % select @name='__id'; ex=$i , DisplayName

      -ArgumentList 1,2,3

      write-host "`r`n======================================`r`n"

      # when called, this block retuns all items from the script block
      # notice that the call is the same but instead of using the array variable we use a local array
      Invoke-Command -Session $s -ScriptBlock % select @name='__id'; ex=$i , DisplayName

      -ArgumentList 1,2,3

      $s | Remove-PSSession


      Can anyone explain to me what i am doing wrong? I cant be the only person caught out by this.







      powershell powershell-remoting






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 21 at 13:52









      marsze

      5,87132042




      5,87132042










      asked Mar 21 at 13:32









      SteveSteve

      502148




      502148






















          1 Answer
          1






          active

          oldest

          votes


















          0














          -ArgumentList does what the name implies, it passes a list of arguments to the command. Each value from that list is, if possible, assigned to a defined parameter. But you only have one parameter defined: $array. Therefore, you only get the first value from the arg list.



          See, this is actually how it's supposed to work (3 arguments bound to 3 parameters):



          Invoke-Command -Session $s -ScriptBlock % select @name='__id'; ex=$i , DisplayName 
          -ArgumentList 1, 2, 3


          So, what you actually want to do is pass one array as one single parameter.



          One way to accomplish that would be:



          -ArgumentList (,(1, 2, 3))


          Final code:



          Invoke-Command -Session $s -ScriptBlock % select @n = '__id'; e = $i, DisplayName 
          -ArgumentList (, (1, 2, 3))


          Another way (in this simple case) would be using the automatic $args variable:



          Invoke-Command -ScriptBlock 
          $args -ArgumentList 1, 2, 3





          share|improve this answer

























          • thanks a lot. I've use the "," before an array before but had completely forgotten about it. still cant remember its name.

            – Steve
            Mar 21 at 13:53










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281599%2finvoke-command-returns-only-a-single-object-when-called-using-scriptblock-and-ar%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          -ArgumentList does what the name implies, it passes a list of arguments to the command. Each value from that list is, if possible, assigned to a defined parameter. But you only have one parameter defined: $array. Therefore, you only get the first value from the arg list.



          See, this is actually how it's supposed to work (3 arguments bound to 3 parameters):



          Invoke-Command -Session $s -ScriptBlock % select @name='__id'; ex=$i , DisplayName 
          -ArgumentList 1, 2, 3


          So, what you actually want to do is pass one array as one single parameter.



          One way to accomplish that would be:



          -ArgumentList (,(1, 2, 3))


          Final code:



          Invoke-Command -Session $s -ScriptBlock % select @n = '__id'; e = $i, DisplayName 
          -ArgumentList (, (1, 2, 3))


          Another way (in this simple case) would be using the automatic $args variable:



          Invoke-Command -ScriptBlock 
          $args -ArgumentList 1, 2, 3





          share|improve this answer

























          • thanks a lot. I've use the "," before an array before but had completely forgotten about it. still cant remember its name.

            – Steve
            Mar 21 at 13:53















          0














          -ArgumentList does what the name implies, it passes a list of arguments to the command. Each value from that list is, if possible, assigned to a defined parameter. But you only have one parameter defined: $array. Therefore, you only get the first value from the arg list.



          See, this is actually how it's supposed to work (3 arguments bound to 3 parameters):



          Invoke-Command -Session $s -ScriptBlock % select @name='__id'; ex=$i , DisplayName 
          -ArgumentList 1, 2, 3


          So, what you actually want to do is pass one array as one single parameter.



          One way to accomplish that would be:



          -ArgumentList (,(1, 2, 3))


          Final code:



          Invoke-Command -Session $s -ScriptBlock % select @n = '__id'; e = $i, DisplayName 
          -ArgumentList (, (1, 2, 3))


          Another way (in this simple case) would be using the automatic $args variable:



          Invoke-Command -ScriptBlock 
          $args -ArgumentList 1, 2, 3





          share|improve this answer

























          • thanks a lot. I've use the "," before an array before but had completely forgotten about it. still cant remember its name.

            – Steve
            Mar 21 at 13:53













          0












          0








          0







          -ArgumentList does what the name implies, it passes a list of arguments to the command. Each value from that list is, if possible, assigned to a defined parameter. But you only have one parameter defined: $array. Therefore, you only get the first value from the arg list.



          See, this is actually how it's supposed to work (3 arguments bound to 3 parameters):



          Invoke-Command -Session $s -ScriptBlock % select @name='__id'; ex=$i , DisplayName 
          -ArgumentList 1, 2, 3


          So, what you actually want to do is pass one array as one single parameter.



          One way to accomplish that would be:



          -ArgumentList (,(1, 2, 3))


          Final code:



          Invoke-Command -Session $s -ScriptBlock % select @n = '__id'; e = $i, DisplayName 
          -ArgumentList (, (1, 2, 3))


          Another way (in this simple case) would be using the automatic $args variable:



          Invoke-Command -ScriptBlock 
          $args -ArgumentList 1, 2, 3





          share|improve this answer















          -ArgumentList does what the name implies, it passes a list of arguments to the command. Each value from that list is, if possible, assigned to a defined parameter. But you only have one parameter defined: $array. Therefore, you only get the first value from the arg list.



          See, this is actually how it's supposed to work (3 arguments bound to 3 parameters):



          Invoke-Command -Session $s -ScriptBlock % select @name='__id'; ex=$i , DisplayName 
          -ArgumentList 1, 2, 3


          So, what you actually want to do is pass one array as one single parameter.



          One way to accomplish that would be:



          -ArgumentList (,(1, 2, 3))


          Final code:



          Invoke-Command -Session $s -ScriptBlock % select @n = '__id'; e = $i, DisplayName 
          -ArgumentList (, (1, 2, 3))


          Another way (in this simple case) would be using the automatic $args variable:



          Invoke-Command -ScriptBlock 
          $args -ArgumentList 1, 2, 3






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 21 at 13:49

























          answered Mar 21 at 13:40









          marszemarsze

          5,87132042




          5,87132042












          • thanks a lot. I've use the "," before an array before but had completely forgotten about it. still cant remember its name.

            – Steve
            Mar 21 at 13:53

















          • thanks a lot. I've use the "," before an array before but had completely forgotten about it. still cant remember its name.

            – Steve
            Mar 21 at 13:53
















          thanks a lot. I've use the "," before an array before but had completely forgotten about it. still cant remember its name.

          – Steve
          Mar 21 at 13:53





          thanks a lot. I've use the "," before an array before but had completely forgotten about it. still cant remember its name.

          – Steve
          Mar 21 at 13:53



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281599%2finvoke-command-returns-only-a-single-object-when-called-using-scriptblock-and-ar%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript