Search This Blog

Sunday, December 25, 2011

Using Batch Files to Automate Networking Tasks - PART3


How to Restart Services On All Domain Controllers Within a Domain

To restart service on all domain controllers within a domain, perform the following steps: 

  1. Create the Restart.bat and Restart2.bat files listed below.
  2. Run the Restart.bat Service Name from a computer running Windows NT using administrator privileges. The Restart.bat file issues the Windows NT Resource Kit utility NETDOM to create a file called Netdom.txt. The Netdom.txt file gets parsed using the FOR command (part of Windows NT command extensions). Each \\DomainControllerName gets passed to the Restart2.bat file where the Windows NT Resource Kit utility NETSVC command gets issued to stop and start the Service Name entered at the command prompt.
Filename: RESTART.BAT 

echo off
cls
if (%1)==() goto NoParams
netdom bdc > netdom.txt
for /F "skip=6 tokens=4" %%a in (netdom.txt) do call restart2.bat
%%a %1
echo ---------
echo - Done! -
echo ---------
goto bottom
:NoParams
echo usage: RESTART "Service Name"
echo.
echo. i.e.- RESTART "License Logging Service"
echo.
:bottom
    

Filename: RESTART2.BAT 

echo Restarting %2 on %1
netsvc %2 %1 /stop
netsvc %2 %1 /start
echo.
  

No comments: