我写了一个小的powershell脚本,从文本文件中读取sql server实例的名称,然后循环它们并将查询结果输出到文本文件。Powershell&nice格式化输出文件
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
}
但是,当调用Invoke-Sqlcmd时,每次都会重新设置文件SqlLoopLog.txt的内容。但是,如果我添加-append,则信息将输出到一行而不是几行,并且它是不可读的。如何输出可读格式的数据?
我已经更新了我的答案 – 2013-02-14 17:23:12