I am pushing a sqlcmd output file successfully to a remote target server. However, I now need to place this output file onto 3 additional servers (cloned, same directory structure). How can I do this?
current output to one destination:
SQLCMD -Q "EXEC [dbo].[PR_plan_cal_fgi]" -S . -d mdm_sat -E -s "," -o "\\uni-adexscp-01t\startup\plan_cal_fgi.csv" -W -h -1
Answer by dc3 ·
If you're using powershell, you can use Tee-Object to achieve multiple output files. There's probably a better way to do it, but this does work for piping local logs to two different destinations, for instance.
First it outputs whatever data to the screen. That output is piped to Tee-Object where you can specify a file path. Next it's piped tot Out-File which will create a separate file.
<insert command to output text> | Tee-Object -filePath <full_path_to_first_file> | Out-File <full_path_to_second_file>
For Example:
Get-Process notepad | Tee-Object -FilePath C:\users\me\desktop\test.txt | Out-File C:\users\me\desktop\test2.txt
The example code above will use Get-Process to find the instances of notepad running on my box and print the output. It will then pipe that output to Tee-Object to create test.txt and then again pipe the output to Out-File to create test2.txt. Presumably if you have a network share you could use that instead of a local file path as I did.
More info here: