title: Powershell - SQL query result to variable with properties
body: <p>Why the stored output of SQLCMD has only <code>Length</code> property instead of <code>column names</code>?. Is it not possible to store <code>sqlcmd</code> output with its properties? </p>
  
  <p><code>Invoke-sqlcmd</code> stores it correctly but <code>Invoke-SQLcmd</code> takes a bit longer to process so I'm trying to make it work with SQLcmd as this method will be part of  different scripts that are scheduled to run every minute, once ever hour etc., </p>
  
  <p>Any idea if this is possible or what the issue is?</p>
  
  <p>Store output and echo $var:</p>
  
  <pre><code>     PS C:&gt; $var=(SQLCMD -S 'x.x.x.x' -U 'user' -P 'password' -i "C:\query.sql" -W -m 1) 
  
       PS C:&gt; $var
       job_id name
       ------ ----
       12345-aaaa-1234-5678-000000000000000 Clear DB entries
       12345-bbbb-1234-5678-000000000000000 TempLog DB
  </code></pre>
  
  <p>Echo $var[0,1,2] which doesn't show property names.</p>
  
  <pre><code>     PS C:&gt; $var[0]
       job_id name
       PS C:&gt; $var[1]
       ------ ----
       PS C:&gt; $var[2]
       12345-aaaa-1234-5678-000000000000000 Clear DB entries
  </code></pre>
  
  <p>Show $var properties</p>
  
  <pre><code>     PS C:&gt; $var | select *
       Length
       ------
       11
       53
  </code></pre>
  
  <p>Show $var type</p>
  
  <pre><code>     PS C:&gt; $var.GetType()
  
       IsPublic IsSerial Name                                     BaseType
       -------- -------- ----                                     --------
       True     True     Object[]                                 System.Array
  </code></pre>