Hello Experts,
I'm by no means a programmer, and have only used batch files to do very basic things in the past. However, I'm attempting to automate maintenance procedures on eight DCs without user/administrator interaction. I would like to run "dcdiag" and "repadmin" on all eight DCs automatically and email a notification to an email distribution list once the jobs have run. Let me outline the steps:
1) I want to locate my batch files on each DC in C:\SCRIPTS. <I got this one..>
2) I want to schedule the batch files on each DC to run once a week. <I got this one...>
3) I want to run "dcdiag" and "repadmin". I want to output the results to two different text files respectively. The name convention I want to use for each of this files is: "NETBIOSname-dcdiag-MMDDYY
.txt" and "NETBIOSname-repadmin-repl
sum-MMDDYY
.txt". <this is my problem!!...>
4) I want to copy the files created in step 3 to a network location \\servername\sharename. <I got this one..>
5) I want to send an automatic email notification to an email distribution list once the schedule task has completed. I researched and came up with BLAT as a way to do this. I tested this on a test machine, and it worked OK. If there's another way to do it without using BLAT, I would like to know. <I'll say that I have this one unless someone has a better way of doing it...>
Here's some code snippets that I've been able to put together:
-----Code to run DCDIAG and output the results-----
@ECHO OFF
DCDIAG /v /e > C:\ADDiag\NETBIOSname-dcdi
ag-MMDDYY.
txt
BLAT NETBIOSname-dcdiag-MMDDYY.
txt -to <username>@<mydomain> -s Subject -priority 1
My biggest challenge has been how to generate the file name automatically to fit my name convention. The following code snippet finds the FQDN and requires the administrator to type the host's IP address.
@ECHO OFF
ECHO.
IF [%1]==[] GOTO Syntax
ECHO.%1 | FIND "?" >NULL
IF NOT ERRORLEVEL 1 GOTO Syntax
FOR /F "tokens=2 delims= " %%A IN ('PING -a %1 -n 1 ^| FIND "[%1]"') DO ECHO.%%A
GOTO:EOF
:Syntax
ECHO.
ECHO Usage: HOSTNAME ^<IP_address^>
ECHO.
Start Free Trial