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

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현