Search This Blog

Sunday, December 25, 2011

Using Batch Files to Automate Networking Tasks - PART1

This article demonstrates a few ways to use Windows NT command extensions in conjunction with Windows NT Resource Kit utilities within batch files to automate common networking tasks. 

The following tasks will be illustrated: 

  • How to automate the addition of Domain\Domain Users global group to each of the member servers Change the system time user right.
  • How to add files to many users' home directories.
  • How to restart services on all domain controllers within a domain.

How to Automate the Addition of Domain\Domain Users

How to automate the addition of "Domain\Domain Users" global group to each of the member servers "Change the system time" user right. 

  1. Create the Addtime.bat and Addtime2.BAT files listed below.
  2. Run Addtime.bat with administrator privileges from a computer running Windows NT. This batch file creates a list of member servers using the Windows NT Resource Kit utility Netdom.exe. The output of NETDOM gets redirected to a file, which in turn, gets parsed using the FOR command (part of Windows NT command extensions). The Addtime2.bat file gets called for each instance of \\ServerName within the Netdom.txt file. The Addtime2.bat file then issues the Windows NT Resource Kit utility Ntrights.exe to add Domain\Domain Users global group to each of the member servers Change the system time user right. The output of NTRIGHTS gets written to a file called Log.txt.
Filename: Addtime.bat 

echo off
cls
echo Creating a list of member servers.
echo.
netdom member > netdom.txt
echo Adding "Change System Time" right to Member Servers...
echo.
if exist log.txt del log.txt
for /F "skip=6 tokens=4" %%a in (netdom.txt) do 
   call ADDTIME2.bat %%a
echo.
echo ----------------------------------------------
echo - Done! Check LOG.TXT for status information.-
echo ----------------------------------------------
    


Filename: ADDTIME2.BAT 

echo Adding right to %1...
ntrights -u "domain users" -m %1 +r SeSystemTimePrivilege >> log.txt
    

No comments: