set sourcedirectory=C:scriptsssbu
set BKUsername=domainusername
set BKPW=enterpasswordhere
set BKDrive=J
set Sharepoint=J$
del SSBU_JOB_STATUS.old
ren SSBU_JOB_STATUS.TXT SSBU_JOB_STATUS.old
del SSBU-Log.old
ren SSBU-Log.txt SSBU-Log.old
echo. >pingtest.tmp
for /f %%a in (dclist%BKdomain%.txt) do (ping -n 1 %%a |find /I «Received = 1») || (echo %%a>> 
pingtest.tmp)
echo ***************************************************** >>SSBU_JOB_STATUS.txt
echo DCs will be listed only if no backup job is found. >>SSBU_JOB_STATUS.txt
echo ***************************************************** >>SSBU_JOB_STATUS.txt
for /f %%a in (dclist.txt) do (set targetserver=%%a) & (schtasks /query /s:%%a |find /I «system-
state-backup») || (call :createjob)
:verifyBKF
echo *********************************************************** >> SSBU-Log.txt
echo If no BKF file is shown under the DC name, none was found. >> SSBU-Log.txt
echo *********************************************************** >> SSBU-Log.txt
for /f «tokens=1,2» %%a in (dclist.txt) do find /I «%%a» pingtest.tmp && (echo. >>SSBU-Log.txt & 
echo %%a is not reachable. >>SSBU-Log.txt) || (
	echo. >> SSBU-Log.txt && echo %%a >> SSBU-Log.txt && dir \%%a\%sharepoint%system-
state-backup*.BKF | find /I «ssbu-»>> SSBU-Log.txt)
REM *******************************************************************************************
REM You can add a section here to email the log files
REM (SSBU_JOB_STATUS.TXT and SSBU-Log.txt)
REM using blat.exe or another SMTP mailer.
REM *******************************************************************************************
goto end
:createjob
find /I «%targetserver%» pingtest.tmp && (echo. >>SSBU_Job_Status.txt & echo %targetserver% 
is not reachable. >>SSBU_Job_Status.txt) || (
	echo. >>SSBU_Job_Status.txt & echo %targetserver%: SSBU job was not present on system 
but recreation was attempted. Please verify... >> SSBU_JOB_STATUS.txt)
md \%targetserver%\%sharepoint%system-state-backupjob
copy %sourcedirectory%ssbu.bat \%targetserver%\%sharepoint%system-state-backupjob.
copy %sourcedirectory%system-state-backup.bks \%targetserver%\%sharepoint%system-
state-backupjob.
schtasks /create /s %targetserver% /sc daily /u %BKUsername% /P %BKPW% /TN System-
State-Backup /ST 02:00:00 /TR «%bkdrive%:system-state-backupjobssbu.bat 1> 
%bkdrive%:system-state-backupjobssbu.LOG 2>&1»
:end