title: PowerShell return a single element array from function
body: <p>Today I noticed an interested behavior of PowerShell and I made the following code to show it. When you run:</p>
  
  <pre><code>function test()
  {
      $a = @(1,2);
      Write-Host $a.gettype()
      return $a;
  }
  
  $b = test
  Write-Host $b.gettype();
  </code></pre>
  
  <p>What you got is:</p>
  
  <pre><code>System.Object[]
  System.Object[]
  </code></pre>
  
  <p>However when you change the code to:</p>
  
  <pre><code>function test()
  {
      $a = @(1);
      Write-Host $a.gettype()
      return $a;
  }
  
  $b = test
  Write-Host $b.gettype();
  </code></pre>
  
  <p>You will got:</p>
  
  <pre><code>System.Object[]
  System.Int32
  </code></pre>
  
  <p>Can someone provide some more details on this "feature"? Seems the PowerShell specification did not mention this.</p>
  
  <p>Thanks.</p>
  
  <hr>
  
  <p>BTW, I tested the code on PowerShell version 2, 3 &amp; 4.</p>