I have a Powershell script that runs some sql files to install tables/stored procedures. Within the PS script I output some text to the log file before each file is run, then perform an Invoke-SqlCmd using -Verbose for the sql file and redirect all output to the same log file. This all works great, and the output from the PS script comes out looking normal, but any output from the sql file (via PRINT or from an error in the DDL) comes out with the letters double-spaced apart. Here is a sample of the output from the log file:
--- Deploying MyTable ----
--- Deploying MyTable.sql...
--- D r o p p i n g t a b l e d b o . M Y T A B L E
--- T a b l e d b o . M Y T A B L E s u c c e s s f u l l y c r e a t e d
Here is the code I am running:
Clear-Host
$sqlServer = Read-Host -Prompt "Enter Server"
$sqlServer
$db = Read-Host -Prompt "Enter Database"
$db
$logFolder = Read-Host -Prompt "Enter log file folder"
$logFolder
$logFileName = "MyTable.txt"
rm $logFolder\$logFileName -ErrorAction Ignore
Add-Content $logFolder\$logFileName "#############################################"
Add-Content $logFolder\$logFileName "### Deploying MyTable ####"
Add-Content $logFolder\$logFileName "#############################################"
Add-Content $logFolder\$logFileName " "
Add-Content $logFolder\$logFileName "Deploying MyTable.sql..."
Invoke-Sqlcmd -ServerInstance $sqlServer -Database $db -InputFile "MyTable.sql" -Verbose *>> $logFolder\$logFileName
Everything works fine, but looks terrible. Any thoughts on how I might resolve the formatting of the output from the PRINT statements and the error messages from the sql?