I wrote a small powershell script that reads name of sql server instances from text-file then loops them and output results of the query to the text file.
foreach ($Instance in Get-Content C:\temp\SQLServers.txt)
{
$Instance;
$File ="c:\temp\SqlLoopLog.txt"
Add-Content $File "`r`n$Instance"
Invoke-Sqlcmd -ServerInstance $Instance -Database msdb -Query "select * from dbo.[sysjobs]" | Out-File $File
}
But when called Invoke-Sqlcmd the content of the file SqlLoopLog.txt is re-set each time. But if I add -append then the information is output in one row instead of the several rows and it is un-readable. How to output data in readable format?