The role of scripting in network administration

Network administrators have used scripting while long before Windows or even DOS came on the scene. UNIX administrators, for example, they have been using shell scripting and its powerful capabilities for decades. Scripting can considerably ease the load 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 article of the scripting guide, I will provide information to help you understand how scripting can play a role in network maintenance and management. In following 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, understand program that can carry out a sequence 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 different 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.

A number of scripting "languages" are available for you to choose from, each with its own capabilities and limitations. These languages include Windows native shell scripting, Visual Basic Scripting Edition, JavaScript, Kixtart, and Perl. Which one you choose will ultimately depend on a combination of the tasks required and your own experience and inclinations.

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

Windows Shell scripting

A shell is nothing more than an interface that allows a user to communicate with, or issue commands directly to, the operating system. The concept of a shell has been around in UNIX for many years. In fact, there are several shells in the UNIX world, each with its own features and commands that make it suitable for various tasks.

In Windows, there is no such diversity. You have only one shell, the Windows shell, which is built into the operating system. And you are undoubtedly already familiar with the interface, although you probably call it the command prompt or, if you're a real old-timer, perhaps the DOS prompt. Technically speaking, it's called a command shell and is run by executing the file Cmd.exe, found in C:\Winnt\System32. Probably the easiest way to run it is to simply click Start | Run, type cmd in the text box, and click OK, or create a shortcut to Cmd.exe.

Visual Basic Scripting Edition

In future articles, I will discuss the basics of using VBS for writing scripts. For the moment, let's take a quick look at what it can do.

VBS is a subset of the full-blown programming language Visual Basic. (Another subset of Visual Basic, called Visual Basic for Applications—VBA—is used primarily to create macros for Microsoft Office applications.) Using the objects and methods found in both the Windows Scripting Host and in VBS, along with correct VBS syntax, you can create a VBS script.

You do this by using a text editor such as Notepad to write out a set of commands and then save the finished script with the file extension .vbs. Once this file is created, you can execute it just as you would any other executable file. For example, you can:

• Double-click on the icon.

• Type the filename at the command prompt.

• Type the name of the file on its own line within a shell script



Java Script

JScript is the Microsoft implementation of JavaScript. JScript and JavaScript are not subsets of the Java programming language. However, like VBS, JScript is an object-based scripting language that can be used to automate tasks for network administration.

You create a JScript file in the same way you create a VBS file, except that you must save it with the file extension .js. The default icon for a JScript file looks just like the icon for a VBS file, except that the VBS icon is blue and the JScript icon is yellow. You execute a JScript file in the same way you execute a VBS file.