The use of cmd files to execute sql is a powerful tool that is underutilized, if the lack of posts is any indicator.
I use cmd files to run almost all SQL Server jobs.
The following example shows how to run a database space report on multiple servers using SQL in a central library. It eliminates the need to create duplicate SQL on each server. All output is piped to the reports directory so you have a record of the job and most errors that occur, if needed.
I create a directory structure on each server as follows:
echo *** VPCJSTINEY: Database Space *** > c:\dbjobs\reports\dbspace.txt
call c:\dbjobs\cmd\sqlcmdcen.cmd master dbspace dbspace
rem *** run sqlcmd: parms - database = %1, input = %2, output = %3 ***
sqlcmd -S localhost -E -w100 -d%1 -i \\fargo\c$\mssqlcen\sql\%2.sql >> c:\dbjobs\reports\%3.txt
The SQL script is not included as it is much longer.