title: Powershell v2 function returns System.Object[] instead of PSCustomObject
body: <p>I am trying to create a function that creates a custom object but have encountered unusual behavior. If you run the below code, you'll find this output</p>
  
  <pre><code>function Test-CustomObject {
      function Create-CustomObject {
  
          $objProps = @{ 
              'property1' = 'Hello from property 1';
              'property2' = 'Hello from property 2';
          }
  
          $obj = New-Object -TypeName PSCustomObject -Prop $objProps
  
          $obj | Add-Member -MemberType ScriptMethod -Value { return 'Hello from method 1' } -Name Method1 -PassThru
          $obj | Add-Member -MemberType ScriptMethod -Value { return 'Hello from method 2' } -Name Method2 -PassThru
  
          write-host "in function: $obj"
          write-host "in function type: $($obj.GetType())"
  
          return $obj
      }
  
      $newObj = Create-CustomObject
      write-host "after function: $newObj"
      write-host "after function type: $($newObj.GetType())"
  }
  
  Test-CustomObject
  </code></pre>
  
  <p>Program Output:</p>
  
  <pre><code>in function: @{property1=Hello from property 1; property2=Hello from property 2}
  in function type: System.Management.Automation.PSCustomObject
  after function:
  after function type: System.Object[]
  </code></pre>
  
  <p>Does anyone know why the returned object is System.Object[] instead of PSCustomObject?</p>