How to Get Started Writing Scripts - 05 Jun 2006
If you're new to scripting and would like to learn how to write Windows shell, VBScript, or Powerscript scripts, here are some resources that might help you.
June 4, 2006
A few weeks ago, I received an email from Randy Culbertson, who noted that he has the desire and time to learn scripting but didn't know where to start. That prompted me to contact several scripting experts so that I could compile a list of resources that Randy 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" (InstantDoc ID 8599) provides an easy-to-understand overview of scripting.
Before I go any further, let me mention two important notes:
I'll be referencing Windows IT Pro, Microsoft, and third-party resources. All the Windows IT Pro articles will have an InstantDoc ID after them. To access these articles, simply go to http://www.windowsitpro.com, enter the specified number in the InstantDoc ID box, and click Go. Normally, most of these articles are available only to subscribers. However, for about a month (from June 2 to July 6), the Windows IT Pro articles I mention in this column will be available for public viewing. Come July 7, they'll be locked down again, so don't put off looking at them.
Some of the articles and books I reference are older. However, even though they may be slightly outdated, they're still good references for learning scripting. To borrow an old cliche, they're "oldies but goodies."
One point that the article "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. In this column, I'll cover the languages of Windows shell scripting and VBScript. For those of you who aren't new to scripting but maybe new to the Windows PowerShell (formerly code-named Monad), I'm including some resources for learning this new command-line shell's scripting language, which is called Powerscript. Next month, I'll discuss the resources for learning JScript, Perl, and T-SQL.
Which languages you should learn depends on the systems you work with. If you work with Windows, I suggest you learn shell scripting and VBScript. If you work with Microsoft SQL Server, you should probably learn shell scripting and T-SQL. Notice that I specified two languages. The more you learn, the better.
Shell Scripting
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 the basics and even includes practical exercises you can try on your own. Here are the links to this series:
"Shell Scripting 101, Lesson 1" (InstantDoc ID 16355)
"Shell Scripting 101, Lesson 2" (InstantDoc ID 19840)
"Shell Scripting 101, Lesson 3" (InstantDoc ID 20142)
"Shell Scripting 101, Lesson 4" (InstantDoc ID 20530)
"Shell Scripting 101, Lesson 5" (InstantDoc ID 20781)
"Shell Scripting 101, Lesson 6" (InstantDoc ID 21310)
"Shell Scripting 101, Lesson 7" (InstantDoc ID 21630)
"Shell Scripting 101, Lesson 8" (InstantDoc ID 21984)
"Shell Scripting 101, Lesson 9" (InstantDoc ID 22289)
"Shell Scripting 101, Lesson 10" (InstantDoc ID 22582)
After you go through that series, you can check out the following articles:
"Getting Started in NT Shell Scripting, Part 1" (InstantDoc ID 8182)
"Getting Started in NT Shell Scripting, Part 2" (InstantDoc ID 8384)
"The FAQs About Setting Up Your Shell Scripting Environment" (InstantDoc ID 49676)
One book that several scripting experts recommended is Tim Hill's book Windows NT Shell Scripting (Macmillan Technical Publishing, 1998).
VBScript
VBScript is a scripting language associated with Windows Script Host. WSH 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 just like any house, there can be visitors. The WSH house visitors include Perl and Python. Whether the people reside in the house or are visitors, they can use the objects in that house. In the WSH house, the people can use objects such as the FileSystemObject object or the WScript object.
Good resources to learn about WSH include
"WSH, Part 1: File Types" (InstantDoc ID 48498)
"WSH, Part 2: .wsf Files" (InstantDoc ID 48692)
"WSH, Part 3: Windows Script Components" (InstantDoc ID 49092)
"Scripting Solutions: Scripting 101" (InstantDoc ID 5410)
"Scripting Solutions: Scripting 101, Part 2" (InstantDoc ID 5505)
"Scripting Solutions: Scripting 101, Part 3" (InstantDoc ID 5683)
"Scripting Solutions: Scripting 101, Part 4" (InstantDoc ID 7112)
"An Introduction to WSH" (InstantDoc ID 4608)
Tim Hill's Windows Script Host, third edition (New Riders Publishing, 2003)
Windows 2000 Scripting Guide (Microsoft Press, 2003). You can find parts of the guide available on the Microsoft Developer Network (MSDN) at http://www.microsoft.com/technet/scriptcenter/guide.
Like the "Shell Scripting 101" series, the "Understanding VBScript" series is a tutorial that you can use to learn VBScript. The following articles cover the basics:
"Understanding VBScript" (InstantDoc ID 5455)
"Understanding VBScript: Arrays" (InstantDoc ID 5627)
"Understanding VBScript: Operators" (InstantDoc ID 5881)
"Understanding VBScript: Statements" (InstantDoc ID 6125)
"Understanding VBScript: Built-In and User-Defined Functions" (InstantDoc ID 6185)
"Understanding VBScript: Functions to Manipulate Strings" (InstantDoc ID 7460)
"Understanding VBScript: Object Management" (InstantDoc ID 7667)
"Understanding VBScript: Manipulating Files with FileSystemObject" (InstantDoc ID 7825)
"Understanding VBScript: The Drive Object" (InstantDoc ID 7992)
"Understanding VBScript: The Folder Object" (InstantDoc ID 8184)
"Understanding VBScript: Working with the File Object" (InstantDoc ID 8389)
"Understanding VBScript: The TextStream Object" (InstantDoc ID 8603)
"Understanding VBScript: The Dictionary Object--An Alternative to Array" (InstantDoc ID 8797)
"Understanding VBScript: Runtime Code Evaluation" (InstantDoc ID 8979)
"Understanding VBScript: Using Regular Expressions" (InstantDoc ID 9170)
"Understanding VBScript: Real-World Uses of Regular Expressions" (InstantDoc ID 9800)
Powerscript
Although Windows PowerShell is still a release candidate, you can start learning about this new command-line shell and its scripting language. There's already been at least one book published: Andy Oakley's Monad Jumpstart (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.
Besides these books, there are some other types of resources available. Microsoft's Channel9 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, Web casts, 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.
This list of shell scripting, VBScript, and Powerscript resources isn't meant to be all-inclusive. It just contains resources that are known to be helpful. If you have come across any other resources that are helpful, please let me know and I'll add them to the list.
Corrections to this Article:
In the email version of this column, there was an inaccurate InstantDoc ID. The InstantDoc ID for the article "Getting Started in NT Shell Scripting, Part 1" should have been 8182. We apologize for any inconvenience this error might have caused.
About the Author
You May Also Like