title: Pipe complete array-objects instead of array items one at a time?
body: <h2>How do you send the output from one CmdLet to the next one in a pipeline as a complete array-object instead of the individual items in the array one at a time?</h2>
  
  <p><strong>The problem - Generic description</strong><br />
  As can be seen in help for <a href="https://technet.microsoft.com/en-us/library/hh847902.aspx">about_pipelines</a> (<code>help pipeline</code>) powershell sends objects one at the time down the pipeline¹. So <code>Get-Process -Name notepad | Stop-Process</code> sends one process at the time down the pipe.</p>
  
  <p>Lets say we have a 3rd party CmdLet (Do-SomeStuff) that can't be modified or changed in any way. Do-SomeStuff perform different if it is passed an array of strings or if it is passed a single string object.</p>
  
  <p><em>Do-SomeStuff is just an example, it could be substituted for <code>ForEach-Object</code>, <code>Select-Object</code>, <code>Write-Host</code> (or any other CmdLet accepting pipeline input)</em></p>
  
  <p>Do-SomeStuff will in this example process the individual items in the array one at the time.</p>
  
  <pre><code>$theArray = @("A", "B", "C")
  $theArray | Do-SomeStuff
  </code></pre>
  
  <p>If we want to send the complete array as one object to Do-SomeStuff one might try something like this</p>
  
  <pre><code>@($theArray) | Do-SomeStuff
  </code></pre>
  
  <p>But it does not produce the expected result since PowerShell "ignores" the new single-item-array.</p>
  
  <p>So, how do you "force" <code>$theArray</code> to be passed down the pipe as a single array-object instead of the content items one at the time?</p>
  
  <p><br />
  <strong>The problem - practical example</strong><br />
  As shown below the output of <code>Write-Host</code> is different if passed an array or if it passed the individual items in the array one at the time.</p>
  
  <pre><code>PS C:\&gt; $theArray = @("A", "B", "C")
  PS C:\&gt; Write-Host $theArray
  A B C
  PS C:\&gt; $theArray | foreach{Write-Host $_}
  A
  B
  C
  PS C:\&gt; @($theArray) | foreach{Write-Host $_}
  A
  B
  C
  </code></pre>
  
  <p>How do you do to get <code>$theArray | foreach{Write-Host $_}</code> to produce the same output as <code>Write-Host $theArray</code> ?</p>
  
  <p><br />
  <br /></p>
  
  <hr>
  
  <p>FOOTNOTES</p>
  
  <ol>
  <li>Pipeline processing in Powershell</li>
  </ol>
  
  <p>A normal array of strings</p>
  
  <pre><code>PS C:\&gt; @("A", "B", "C").GetType().FullName
  System.Object[]
  </code></pre>
  
  <p><br />
  A normal array of strings piped to Foreach-Object</p>
  
  <pre><code>PS C:\&gt; @("A", "B", "C") | foreach{$_.GetType().FullName}
  System.String
  System.String
  System.String
  </code></pre>
  
  <p>Each string in the array is processed one at the time by the ForEach-Object CmdLet.</p>
  
  <p><br />
  An array of arrays, where the "inner" arrays are arrays of strings.</p>
  
  <pre><code>PS C:\&gt; @(@("A", "B", "C"), @("D", "E", "F"), @("G", "H", "I")) | foreach{$_.GetType().FullName}
  System.Object[]
  System.Object[]
  System.Object[]
  </code></pre>
  
  <p>Each array in the array is processed one at the time by the ForEach-Object CmdLet, and the content of each sub-array from the input is handled as one object even though it is an array.</p>