title: Powershell Formatting Invoke-sqlcmd
body: <p>I'm creating a script to grab info from multiple SQL servers an pump it to a file that users can get to and not have to call me all the time. the problem I am running into right now is formatting the output of the invoke-sql command so I can put it into a hashtable. I want to get the SQL version in one column (i.e. Microsoft SQL Server 2008) and the second column to have the build number (i.e. 10.0.5512.0). What follows is the code I've created and what it outputs. As you can see I get the info but cannot put it into a hashtable. It just puts ... in the table.</p>
  
  <pre><code>$SQLVerPart1= Invoke-Sqlcmd -Query "select @@VERSION;" -ServerInstance $Server | Out-String | ForEach-Object { $_ -replace '-.*'}
  
  $SQLVerPart2 = Invoke-Sqlcmd -Query "select SERVERPROPERTY ('productversion')" -ServerInstance $Server | Out-String 
  
  $SQLVerPart1 | Out-File -Append $Log
  $SQLVerPart2 | Out-File -Append $Log
  $SQLVer.add($SQLVerPart1,$SQLVerPart2)
  </code></pre>
  
  <p>OUTPUT:</p>
  
  <blockquote>
    <p>Column1                                                               </p>
    
    <p>Microsoft SQL Server 2008 (SP3) </p>
    
    <p>Column1                                                               </p>
    
    <hr>
    
    <p>10.0.5512.0                                                                                                                                                           </p>
    
    <p>Name                           Value                                  </p>
    
    <p>----                           -----                                                                                                                                   ...                            ...</p>
  </blockquote>