title: Force Powershell function to return Array
body: <p><br />How can i force a Powershell function to return an Array?
  <br />This simple function for Example, if "C:\New folder" contains only 1 element, it will not return an Array.
  <br/></p>
  
  <pre><code>function Get-AlwaysArray
  {
      $returnArray = gci "C:\New folder"
      Write-Output $returnArray
  }
  (Get-AlwaysArray).Gettype()
  </code></pre>
  
  <p>There is already a Thread with a pretty good upvoted answer <a href="https://stackoverflow.com/questions/11107428/how-can-i-force-powershell-to-return-an-array-when-a-call-only-returns-one-objec">here</a> But non of the answer works unfortunally.
  <br/>Here is what i have tried:</p>
  
  <pre><code>function Get-AlwaysArray {
      [Array]$returnArray = gci "C:\New folder"
      Write-Output $returnArray   
  }
  (Get-AlwaysArray).Gettype()
  
  function Get-AlwaysArray {
      $returnArray = @(gci "C:\New folder")
      Write-Output @($returnArray)   
  }
  (Get-AlwaysArray).Gettype()
  
  function Get-AlwaysArray {
      $returnArray = @(gci "C:\New folder")
      Write-Output @($returnArray | Where-Object {$_})   
  }
  (Get-AlwaysArray).Gettype()
  
  function Get-AlwaysArray {
      [Object[]]$returnArray = @(gci "C:\New folder")
      Write-Output @($returnArray | Where-Object {$_})   
  }
  (Get-AlwaysArray).Gettype()
  </code></pre>
  
  <p>The only way it would work is </p>
  
  <pre><code>function Get-AlwaysArray {
      $returnArray = gci "C:\New folder"
      Write-Output $returnArray 
  }
  @(Get-AlwaysArray).Gettype()
  </code></pre>
  
  <p>But i dont want to add this, everytime i call my function.
  <br /> What am i doing wrong?</p>