:: ******************************************************** :: * Config.cmd - configuration variables for Install.cmd :: * (C) 2013-2018 Richard Swinbank :: * http://richardswinbank.net/dos/installer :: ******************************************************** :: ******* target aliases ****** SET DEV=localhost\INSTANCE SET TEST=MyTestServer\INSTANCE SET PROD=MyProdServer\INSTANCE :: ******** set log file name ***************************** SET LogFile= :: check we have WMIC WMIC.EXE Alias /? >NUL 2>&1 || GOTO setLogFile :: We only want line 2 of WMIC's output - we're using FOR here because we :: want the "tokens" functionality. "skip=1" starts from line 2, IF x%%L==x... :: breaks out at line 3 -- i.e. we only go round the loop once. FOR /F "skip=1 tokens=1-6" %%G IN ('WMIC Path Win32_LocalTime Get Day^,Month^,Year^,Hour^,Minute^,Second /Format:table') DO ( IF x%%L==x GOTO gotDateTokens SET yy=%%L SET dd=00%%G SET mm=00%%J SET hr=00%%H SET min=00%%I SET sec=00%%K ) :gotDateTokens :: reduce 00-padded strings to rightmost two characters SET mm=%mm:~-2% SET dd=%dd:~-2% SET hr=%hr:~-2% SET min=%min:~-2% SET sec=%sec:~-2% SET LogFile=_%yy%%mm%%dd%%hr%%min%%sec% :setLogFile SET LogFile=deploy%LogFile%.log :: ******** set prompt options **************************** SET PROMPT=YES IF x%2==x GOTO targets IF %2==-q ( SET PROMPT=NO GOTO targets ) ECHO Invalid option "%2" GOTO error :: ******** set deployment target ************************* :targets SET DbServer=!%1! IF x%DbServer%==x ( ECHO Target alias "%1" not defined GOTO error ) :: ******** find SQLCMD executable ************************ SET SqlCmd=C:\Program Files\Microsoft SQL Server\110\Tools\Binn\SQLCMD.EXE WHERE SQLCMD > sqlcmdpath.txt 2>&1 IF !ERRORLEVEL! EQU 0 SET /P SqlCmd=