title: Unable to Write Out to PSObject an Array of Data pulled from DB2 database using IBM.Data.DB2 Connector
body: <p>I'm able to extract the data to a CSV file directly when I use  $extractFile = 'D:\TEST\Q_sampler_result_file.csv' when I use Export-CSV to direct to $extractFile.</p>
  <p>What is wrong  with how  I'm  using PSObject to bring this  same table  into an array which I would then, if successful direct to an HTML email?</p>
  <pre><code>Windows PowerShell
  Copyright (C) 2009 Microsoft Corporation. All rights reserved.
  
  PS C:\Users\ME&gt; $factory = [System.Data.Common.DbProviderFactories]::GetFactory(&quot;IBM.Data.DB2&quot;)
  PS C:\Users\ME&gt; $cstrbld = $factory.CreateConnectionStringBuilder()
  PS C:\Users\ME&gt; $cstrbld.Database = 'dbname'
  PS C:\Users\ME&gt; $cstrbld.UserID = 'ME'
  PS C:\Users\ME&gt; $cstrbld.Password = 'PWD'
  PS C:\Users\ME&gt; $cstrbld.Server = 'AIXbox:50001'
  PS C:\Users\ME&gt; $dbconn = $factory.CreateConnection()
  PS C:\Users\ME&gt; $dbconn.ConnectionString = $cstrbld.ConnectionString
  PS C:\Users\ME&gt; $dbconn.Open()
  PS C:\Users\ME&gt; $dbcmd = $factory.CreateCommand()
  PS C:\Users\ME&gt; $dbcmd.Connection = $dbconn
  PS C:\Users\ME&gt; ########################################################################################################################################
  PS C:\Users\ME&gt; #DEMONSTRATE --&gt; showing count of how many failed work units in  Application.PFKIWORKUNIT
  PS C:\Users\ME&gt; $dbcmd.CommandText = 'SELECT PFIWORKUNIT,ACTOR,FLOWDEFINITION,WORKTITLE,STATUS FROM LAWSON.PFIWORKUNIT WHERE STATUS BETWEEN 0 AND 3'
  PS C:\Users\ME&gt; ########################################################################################################################################
  PS C:\Users\ME&gt; $dbcmd.CommandType = [System.Data.CommandType]::Text
  PS C:\Users\ME&gt; $da = $factory.CreateDataAdapter()
  PS C:\Users\ME&gt; $da.SelectCommand = $dbcmd
  PS C:\Users\ME&gt; $ds = New-Object System.Data.DataSet
  PS C:\Users\ME&gt; $rowCount = $da.Fill($ds)
  PS C:\Users\ME&gt; $dbconn.Close()
  PS C:\Users\ME&gt;
  PS C:\Users\ME&gt; write-host $rowCount
  10 ##&lt;-- There are TEN rows of data with the five columns named below
  PS C:\Users\ME&gt;
  PS C:\Users\ME&gt; if($rowCount -gt 0) {
  &gt;&gt;
  &gt;&gt;
  &gt;&gt; $exportObject=@()
  &gt;&gt; $Object = New-Object PSObject
  &gt;&gt; $ds | ForEach{
  &gt;&gt;         $Object | Add-Member -MemberType NoteProperty -Name &quot;PFIWORKUNIT&quot; -Value $row.PFIWORKUNIT
  &gt;&gt;         $Object | Add-Member -MemberType NoteProperty -Name &quot;ACTOR&quot; -Value $row.ACTOR
  &gt;&gt;         $Object | Add-Member -MemberType NoteProperty -Name &quot;FLOWDEFINITION&quot; -Value $row.FLOWDEFINITION
  &gt;&gt;         $Object | Add-Member -MemberType NoteProperty -Name &quot;WORKTITLE&quot; -Value $row.WORKTITLE
  &gt;&gt;         $Object | Add-Member -MemberType NoteProperty -Name &quot;STATUS&quot; -Value $row.STATUS
  &gt;&gt;         $exportObject += $Object
  &gt;&gt; }
  &gt;&gt;
  &gt;&gt;
  &gt;&gt; write-host $exportObject
  &gt;&gt; }
  &gt;&gt;
  @{PFIWORKUNIT=; ACTOR=; FLOWDEFINITION=; WORKTITLE=; STATUS=} ##&lt;-- listing out ONLY Headers of Columns
  
  
  </code></pre>