Network administrators have used scripting since long before Windows or even DOS came on the scene. UNIX administrators, for instance, have been using shell scripting and its powerful capabilities for decades. Scripting can significantly ease the burden of network administration. But learning to create useful and effective scripts for networking tasks is not easy and requires a lot of patience and practice. Before you begin, it’s important to have a good understanding of what scripting is and why it is so useful.
In this first article of my series on scripting, I will provide information to help you understand how scripting can play a role in network maintenance and management. In subsequent articles, I will talk about the various scripting languages and platforms, basic programming concepts for scripting, and using Windows shell scripting and Visual Basic scripting for network administration. I’ll also point you toward other resources that are available for learning how to write scripts.
What is scripting?
Simply stated, a script is a small, interpreted program that can carry out a series of tasks and make decisions based on specific conditions it finds. By “interpreted,” we mean that when it is run, it is carried out one line at a time, as opposed to “compiled,” which is the process of turning it into machine language before it is run. A script is created using ASCII text, so Windows Notepad or a similar text editor is the only tool required.
Each scripting language has a collection of commands or keywords and a set of rules on how to use them. The set of rules for writing a script in any given language is called the syntax. Once you learn the keywords and syntax, you can use a text editor to write the script and then save it with a file extension that is appropriate to the scripting language you are using. Some of the more common file extensions you will see are .bat, .cmd, .vbs, .js, and .kix.
How is scripting used?
Scripting lets you automate various network administration tasks, such as those that are performed every day or even several times a day. For example, login scripts run every time a user logs in to the network and can perform tasks like mapping network drives for the user based on certain conditions, such as group membership. Another example of script use might be a situation where you want to have each Windows NT server create a new Emergency Restore Disk and then copy the contents of that disk to a network location.
Other tasks might need to be carried out only once, such as a modification to the registry, but to a large number of servers that are widely distributed geographically. In a case like that, you could create and distribute a single script to run the task on each server.
You can start scripts manually, but you can also start them automatically, either by a specific event or scheduled via the Windows Task Scheduler. Windows NT allows scripts to be run automatically each time a user logs in to the network. Windows 2000 goes much further and can be configured to automatically run separate scripts upon:
- Machine startup
- Machine shutdown
- User login
- User logout
You could, for instance, map specific network drives when a user logs in and then automatically copy that user’s Favorites folder to a network share when he or she logs out so that the data is preserved in a central location.
The scripting advantage
Scripting in network administration offers significant advantages. It allows you to:
- Save time—Scripts can carry out complex tasks and be invoked automatically, without the intervention of the network administrator, so the admin can concentrate on other tasks while the script runs.
- Be consistent—A script need be written only once and can then be invoked many times. It is much less error-prone than manually carrying out the task each time.
- Be flexible—Scripts can use decision-making logic to respond to different conditions. Rather than statically mapping a workstation to persistent drives, for example, network drives can be mapped in a variety of ways based on which user is logging on to the machine. You could write a script to check whether a file exists and delete it if it does or display an error message if it doesn’t. The only real limit to scripting is your imagination.
As you can see, learning to create scripts for automating network administration is well worth the effort, even if it does require some work. In my next article, I will discuss the various choices you have in scripting languages and platforms.
Subscribe to the Microsoft Weekly Newsletter
Be your company's Microsoft insider by reading these Windows and Office tips, tricks, and cheat sheets. Delivered Mondays and Wednesdays