Photo by Steve Keys
I’ve spent most of my programming career working with system administrators, usually writing tools to automate one process or another. I’ve worked with many tools to accomplish these tasks, from the simply mundane to the hellishly complex. Here’s a survey of some of the more common tools for Windows system administrators. Each has their own strengths and weaknesses, and they’re as individual as administrators themselves.
Most, if not all, administrators at one time or another have worked with the built in batch language of the Windows shell. Batch files are simple text files that have the extension .bat or .cmd. They are executed by the Windows command prompt executable, command.exe or cmd.exe. The batch language itself is very limited (to put it mildly.) It does have looping and branching, but these are rarely used. Most people use it as a way to store a set of commands that they need to run repeatedly, possibly with a few variables thrown in for good measure.
One of its greatest strengths is how easy it is to create a very simple script, another is that these scripts can run on virtually any Windows machine. However, the learning curve grows extremely steep once you get past the world of the “very simple.” It’s a good idea for all administrators to get a thorough grasp of using variables and simple if & for loops. Not only are they handy in a pinch, but you may find yourself needing to change someone else’s script.
Microsoft’s first attempt to grow past the limitations of batch was VBScript. Not only is it a better language to work with than batch but it has access to the myriad of COM objects which were popping up everywhere. Many applications had COM interfaces that could be used by VBScript giving access to features that weren’t availble on a command line. There are many very powerful scripts floating out there. I’ve worked with some that are over 30,000 lines long (worked *with* not *on*, I don’t think I’d dare venture into that mess.)
VBScript was quite successful in the system administrator community, though it’s not the most powerful language in the world. It’s a simple language, and one that would still behoove most admins to at least get familiar with. Its one drawback nowadays is that it doesn’t have any decent access to the newer .NET interfaces coming on the market.
PowerShell is an intended replacement for both batch and VBScript. Not only can it do everything its predecessors can, it is also tightly woven within .NET giving access to the interfaces of the future. It’s a very powerful language in its own right, with some very advanced features. No longer can hard core developers snicker behind the backs of their sys-admin brethren and their “toy” languages. PowerShell is a full-fledged member of the “Yeah, but can your language do this?” family.
PowerShell is only now starting to get spread out in the world enough to make it useful. It ships with all Windows 2008 servers, though strangely it’s not installed by default. If you’re looking to keep up with the cutting edge, spending some time learning PowerShell would be a great investment.
C# and VB.NET
While these may not be considered scripting languages in the strictest sense, they’re still something to consider. Microsoft provides free Express versions of each which can be used for a variety of automation tasks. Particularly useful if the task involves creating a user interface. This is really blurring the lines between administration and development, but it would be beneficial for a lot of system administrators to get some exposure to this side of the fence.
WinBatch is a product which provides some very comprehensive access for scripting Windows. Its real strengths are in its ability to manipulate the Windows interface (pushing buttons, filling out forms, standing in line) and accessing low level details such as security and file system information. Its language isn’t quite as powerful as VBScript, but it makes up for it with the extreme depth and breadth of what you can access. It is a commercial product, with a somewhat overbearing license scheme, but with a loyal following.
AutoIt is an open source product for automating the interface, similar to WinBatch. I’m not terribly familiar with it, having not used it and only hearing about it second hand, but apparently it’s very powerful. Many administrators swear by it, and it would be something worth taking a look at if you have the need to manipulate the interface.
Perhaps not too surprisingly there are versions of Bash for Windows. Bash is the Bourne Again SHell, and is the most popular scripting shell in the UNIX world. The version I’ve used the most comes with Cygwin (which is another tool every admin should have in their box.) If you’ve come from the UNIX world or if you keep a foot there, this would be a good option to consider.
Other Scripting Languages
Most popular scripting languages have Windows versions available, such as Python, Ruby, Tcl, and Perl. These provide varying levels of functionality for administrators and may be good choices if there are readily available resources, such as within a company that uses one of the languages extensively for other purposes. Any one of them can make a good choice for an administrator to pick up.
Well, there you have it. I’m sure I’ve left something out, so feel free to put in a comment about your favorite automation tool.