A few months ago, I received an email message from a reader saying that he has the desire and time to learn scripting but doesn't know where to start. That message prompted me to contact several scripting experts and compile a list of resources that this reader and others could use to learn scripting in the Windows environment.
To begin, it helps to know the basic concepts behind scripting. The article "An Introduction to Scripting Technologies and Object Models" (May 2000, InstantDoc ID 8599) provides an easy-to-understand overview of scripting. Before I go any further, however, let me mention two important notes:
- I reference Windows Scripting Solutions, Windows IT Pro, Microsoft, and third-party resources. All the Windows Scripting Solutions and Windows IT Pro article references include an InstantDoc ID. To access these articles, simply go to http://www.windowsitpro.com, enter the specified number in the InstantDoc ID box at the top of the page, and click Go. As a Windows Scripting Solutions subscriber, you can access all Windows Scripting Solutions articles. For the benefit of readers who aren't also Windows IT Pro subscribers, I'm making all the Windows IT Pro articles I mention available for public viewing until October 2.
- Some of the articles and books I mention aren't recent, but they're still good references for learning scripting. To borrow an old cliche, they're "oldies but goodies."
One point that "An Introduction to Scripting Technologies and Object Models" brings up is that there are different scripting languages. Because many scripting languages exist, I decided to narrow the list. I cover the languages of Windows shell scripting, VBScript, JScript, Perl, and T-SQL. For those of you who aren't new to scripting but who haven't had a chance to start working with Windows PowerShell (formerly code-named Monad), I also include some resources for learning this new command-line shell's scripting language, which is called Powerscript.
Which languages you should you learn depends on the systems you work with. If you work with Windows, I suggest you start by learning shell scripting and VBScript. If you work with Microsoft SQL Server, you should probably start with shell scripting and T-SQL. Note that I specified two languages in each case. As with chocolate and potato chips, getting just a taste of learning makes you hungry for more.
The scripting language that the Windows command processor (cmd.exe) uses is often referred to as Windows shell scripting. The 10-part series "Shell Scripting 101" is an excellent tutorial for people who want to learn to write .bat and .cmd scripts. (If you're wondering about the difference between .bat and .cmd scripts, read Lesson 2.) This series walks you through the basics and even includes practical exercises you can try on your own. The articles in this Web-exclusive series are
- "Shell Scripting 101, Lesson 1," January 2001, InstantDoc ID 16355
- "Shell Scripting 101, Lesson 2," February 2001, InstantDoc ID 19840
- "Shell Scripting 101, Lesson 3," March 2001, InstantDoc ID 20142
- "Shell Scripting 101, Lesson 4," April 2001, InstantDoc ID 20530
- "Shell Scripting 101, Lesson 5," May 2001, InstantDoc ID 20781
- "Shell Scripting 101, Lesson 6," June 2001, InstantDoc ID 21310
- "Shell Scripting 101, Lesson 7," July 2001, InstantDoc ID 21630
- "Shell Scripting 101, Lesson 8," August 2001, InstantDoc ID 21984
- "Shell Scripting 101, Lesson 9," September 2001, InstantDoc ID 22289
- "Shell Scripting 101, Lesson 10," October 2001, InstantDoc ID 22582
After you go through that series, I suggest checking out the following articles:
- "Getting Started in NT Shell Scripting, Part 1," March 2000, InstantDoc ID 8182
- "Getting Started in NT Shell Scripting, Part 2," April 2000, InstantDoc ID 8384
- "The FAQs About Setting Up Your Shell Scripting Environment," May 2006, InstantDoc ID 49676
One book that several scripting experts recommend is Tim Hill's Windows NT Shell Scripting (Macmillan Technical Publishing, 1998).
VBScript is associated with Windows Script Host (WSH), which is an environment for executing scripts. I like to think of WSH as a house. A house contains people and objects (e.g., furniture, appliances). In the WSH house, the scripting languages are the people. Two people permanently reside in that house: VBScript and JScript. And as with any house, there can be visitors. Visitors to the WSH house include Perl and Python. Whether people reside in the house or are visitors, they can use the objects in that house. In the WSH house, scripting languages can use objects such as the FileSystemObject object, the WScript object, or the Dictionary object.
Good resources for learning about WSH include
- "WSH, Part 1: File Types," January 2006, InstantDoc ID 48498
- "WSH, Part 2: .wsf Files," February 2006, InstantDoc ID 48692
- "WSH, Part 3: Windows Script Components," March 2006, Instant-Doc ID 49092
- Scripting Solutions, "Scripting 101," Windows IT Pro, June 1999, Instant-Doc ID 5410
- Scripting Solutions, "Scripting 101, Part 2," Windows IT Pro, July 1999, InstantDoc ID 5505
- Scripting Solutions, "Scripting 101, Part 3," Windows IT Pro, August 1999, InstantDoc ID 5683
- Scripting Solutions, "Scripting 101, Part 4," Windows IT Pro, September 1999, InstantDoc ID 7112
- "An Introduction to WSH," December 1998, InstantDoc ID 4608
- Tim Hill's Windows Script Host (Sams Publishing, 2003)
- Microsoft Windows 2000 Scripting Guide (Microsoft Press, 2003). You can find parts of this book on the Microsoft Developer Network (MSDN) Web site at http://www.microsoft.com/technet/scriptcenter/guide.
Like the "Shell Scripting 101" series, the "Understanding VBS" series is a tutorial that you can use to learn VBScript. The following articles cover the basics:
- "Understanding VBScript," June 1999, InstantDoc ID 5455
- "Understanding VBScript: Arrays," July 1999, InstantDoc ID 5627
- "Understanding VBScript: Operators," August 1999, InstantDoc ID 5881
- "Understanding VBScript: Statements," September 1999, Instant-Doc ID 6125
- "Understanding VBScript: Built-In and User-Defined Functions," October 1999, InstantDoc ID 6185
- "Understanding VBScript: Functions to Manipulate Strings," November 1999, InstantDoc ID 7460
- "Understanding VBScript: Object Management," December 1999, InstantDoc ID 7667
- "Understanding VBScript: Manipulating Files with FileSystemObject," January 2000, InstantDoc ID 7825
- "Understanding VBScript: The Drive Object," February 2000, InstantDoc ID 7992
- "Understanding VBScript: The Folder Object," March 2000, InstantDoc ID 8184
- "Understanding VBScript: Working with the File Object," April 2000, InstantDoc ID 8389
- "Understanding VBScript: The TextStream Object," May 2000, InstantDoc ID 8603
- "Understanding VBScript: The Dictionary Object—An Alternative to Arrays," June 2000, InstantDoc ID 8797
- "Understanding VBScript: Runtime Code Evaluation," July 2000, Instant-Doc ID 8979
- "Understanding VBScript: Using Regular Expressions," August 2000, InstantDoc ID 9170
- "Understanding VBScript: Real-World Uses of Regular Expressions," September 2000, InstantDoc ID 9800
Like VBScript, JScript is a scripting language associated with WSH. Consequently, you might expect to see some WSH references in a list of JScript resources. However, most WSH resources don't include information about JScript. For example, Tim Hill's Windows Script Host is highly recommended for learning WSH and VBScript but doesn't include any information helpful in learning JScript. Surprisingly, even the Windows scripting bible—Microsoft Windows 2000 Scripting Guide—contains no information about JScript.
If you run into problems learning JScript, you can talk with fellow scripters at the Windows IT Pro Scripting forum (http://forums.windowsitpro.com). This forum covers all types of scripting languages, so it's a good Web site to bookmark in your browser.
Perl is one of the harder scripting languages to learn. However, it offers some benefits, such as being able to run your scripts on platforms such as Linux and Macintosh as well as on Windows. Roth Consulting's "PERL: The Practical Extraction & Reporting Language" Web page (http://www.roth.net/perl) discusses some other benefits of using Perl. This Web page also has a link to the ActiveState Web site, which offers a free, ready-to-install distribution of Perl called ActivePerl. One of the most popular Perl distributions, ActivePerl includes not only the core Perl engine but also some popular Perl modules and the Perl Package Manager (PPM) for installing Comprehensive Perl Archive Network (CPAN) modules.
If you're a Perl newbie, you might be wondering what modules are. Perl modules are reusable software components that offer specific functionality. For example, the Win32::Perms module lets you modify permissions on files, directories, registry keys, network shares, and shared printers. The only way you can take advantage of a Perl module's functionality is through a Perl script—you can't run modules by themselves. The CPAN Web site (http://www.cpan.org) offers a large collection of Perl modules. The PPM for CPAN lets you install a Perl module from that Web site by typing a simple command.
After you've installed a Perl distribution, you're ready to learn Perl. The book to start with depends on your background:
- If you aren't familiar with programming concepts and would like to use Perl on cross platforms, check out Learning Perl, 4th ed. (O'Reilly, 2005) by Randal L. Schwartz, Tom Phoenix, and Brian D. Foy.
- If you're already familiar with programming concepts and want to use Perl on cross platforms, check out Programming Perl, 3rd ed. (O'Reilly, 2000) by Larry Wall, Tom Christiansen, and Jon Orwant. This book is considered the Perl bible.
- If you aren't familiar with programming concepts and would like to use Perl on the Win32 platform only, check out Learning Perl on Win32 Systems (O'Reilly, 1997) by Randal L. Schwartz, Erik Olson, and Tom Christiansen.
After you have a basic understanding of the Perl language, you can focus on areas of interest to you. For Windows systems administrators, two books of interest are
- Dave Roth's Win32 Perl Programming: The Standard Extensions, 2nd ed. (New Riders, 2001). This book covers many of the standard Win32-specific modules that come with Perl.
- Dave Roth's Win32 Perl Scripting: The Administrator's Handbook, 2nd ed. (New Riders, 2000). This book discusses how to use Perl to automate common tasks that Windows administrators face.
DBAs will want to check out Programming the Perl DBI (O'Reilly, 2000) by Alligator Descartes and Tim Bunce. This book covers the Perl Database Interface (DBI), a Perl-specific interface that provides database functionality.
If you run into problems learning Perl, I suggest visiting some of the many newsgroups and forums in which you can talk with Perl enthusiasts. Besides the Windows IT Pro Scripting forum, you can check out the forums and newsgroups listed on the Win32 Perl Links Web page (http://www.roth.net/perl/links).
T-SQL is the built-in scripting language of Microsoft SQL Server. T-SQL underwent some major changes in SQL Server 2005, so if you want to learn this scripting language, it's best to learn the 2005 version. One recently released book that might help you do so is Beginning Transact-SQL With SQL Server 2000 and 2005 (Wrox Press, 2005) by Paul Turley and Dan Wood. None of the scripting experts I talked with are familiar with this book, but it received an average rating of 4 stars on Amazon.com. Another resource is SQL Server 2005 Books Online (BOL). You can download BOL for free at http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx.
Because T-SQL is based on SQL, getting an idea of how SQL works can be helpful. To get a background on SQL, you can check out Robert Sheldon's SQL: A Beginner's Guide, 2nd ed. (McGraw-Hill Osborne Media, 2003). Note, though, that this book won't help you learn T-SQL syntax.
If you run into problems learning T-SQL, you can ask questions on the SQL Server Magazine T-SQL forum at http://sqlforums.windowsitpro.com/web/forum/default.aspx?forumid=10. You can also interact directly with TSQL master Itzik Ben-Gan through his blog, Puzzled by T-SQL, at http://www.sqlmag.com. For a list of T-SQL newsgroups and Web sites, go to http://www.insidetsql.com/resources.htm.
Although Windows PowerShell is still a release candidate, you can start learning about this new commandline shell and its scripting language. At least one book has already been published: Andy Oakley's Monad (O'Reilly, 2005). Another book, Windows PowerShell in Action, is tentatively scheduled for publication in November by Manning Publications. Bruce Payette, a member of the Windows PowerShell team, is writing this book. You can read an unedited chapter at http://www.manning.com/payette.
Other types of resources are also available. Microsoft's Channel9 (http://channel9.msdn.com) has some good basic information about PowerShell. The Windows Power Shell Wiki (http://channel9.msdn.com/wiki/default.aspx/Channel9.WindowsPowerShellWiki) includes download information and a link to an FAQ Web page. The Microsoft TechNet Script Center offers the "Scripting with Windows PowerShell" Web site (http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx), which includes links to articles, Webcasts, and scripts.
Other useful resources are newsgroups and blogs. You can find the microsoft.public.windows.powershell newsgroup on news.microsoft.com. If you don't use a standard newsreader, you can use the Web interface at http://support.microsoft.com/newsgroups/newsReader.aspx?dg=microsoft.public.windows.powershell. PowerShell blogs include the Windows PowerShell blog at http://blogs.msdn.com/powershell and the PowerShelled blog at http://mow001.blogspot.com.
A Work in Progress
This list of shell scripting, VBScript, JScript, Perl, T-SQL, and Powerscript resources isn't meant to be all-inclusive. But it does offer resources that are known to be helpful when you're learning these scripting languages. If you've come across any other useful resources, please let me know and I'll add them to the list.