I have a quick and dirty Powershell script for running sql scripts against many servers sequentially. I have the servers stored in an array, and loop through them with ForEach. The ForEach roughly looks like this:
ForEach ($Server in $ServerList) {
Write-Host "Executing $Script against $Server..."
Invoke-SqlCmd ........
}
But the problem I have is my output looks something like this:
Executing script.sql against Server1
Executing script.sql against Server2
Executing script.sql against Server3
<Output from Server1>
<Output from Server2>
<Output from Server3>
Executing script.sql against Server4
<Output from Server4>
Executing script.sql against Server5
<Output from Server5>
...you get the idea. Is there any way to marry up the outputs so that the output appears under the message depicting which server is currently being executed on? It would help with using output for debugging etc. Executing on PS7 by the way.