Simplify administrative tasks
This month, I look at 10 essential Windows NT command-script techniques. Command scripts are ASCII text files that contain a group of NT commands. Command scripts can help you automate administrative tasks, such as creating users or shares or running a backup.
10.
Adding comments to a script lets you help others understand what your script does and helps you remember the purpose of older scripts. Use double colons (::) or a Rem statement to add comments to a script.
:: Filename: myfile.bat
rem This batch was created on 03/12/99
9.
The Echo command lets you control NT's default echo functionality. By default, NT displays all commands onscreen unless you explicitly turn off the capability. Echo Off turns off all echoing, except those commands that start with Echo. @Echo Off turns off echoing for the command that follows.
@echo off
echo Command file processing is starting
8. The Goto command and tags let you add structure to your command files. Goto branches to the tag that the Goto statement specifies.
goto error
:error
7. Command-line parameters let you give command files flexibility and reusability. For instance, a command file that adds users might accept a username as a parameter so that different users can use the same script. Command-line parameters start with the percent sign (%), followed by the ordinal number of the parameter.
net user %1 /add
6. Environment variables let you retrieve settings from the system's environment and substitute values when the script runs. You use the Set command to create a new environment variable. You use the variable name between % symbols to retrieve the contents of an environment variable.
set user=tempuser
net user %user% /add