I am running a query in a PowerShell loop and after each execution, I want to write the results to a file. I am using the following:
$accounts = invoke-sqlcmd -ServerInstance $server -Database $database -Query "$sql"
$accounts | Add-Content -Path $outTextFile
but the contents of the file is just n rows (one for each data row) that all contain "System.Data.DataRow" (without the quotes).
I want to write the output (a single column) with no formatting, no headers, just the values returned from the query.
Also, I don't know if the query will add any padding to the end of the results, but is there some way I can force the output to be a specific length (in this case, 26 bytes + CRLF)?