question

fooangel avatar image
fooangel asked

How do I place ONE sqlcmd output file to multiple server destinations?

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

sqlcmdcopy
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
dc3 avatar image
dc3 answered

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:

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/tee-object?view=powershell-7.1

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.