IntroductionNetwork administrators and consultants are confronted with numerous mundane and timeconsuming activities on a daily basis. Whether it is going through thousands of users in Active Directory Users and Computers to grant dial-in permissions to a select group, or changing profile storage locations to point to a newly added network server, these everyday tasks must be completed. In the enterprise space, the ability to quickly write and deploy a Microsoft Visual Basic Script (VBScript) will make the difference between a task that takes a few hours and one that takes a few weeks. As an Enterprise Consultant for Microsoft Corporation, I am in constant contact with some of the world's largest companies that run Microsoft software. The one recurring theme I hear is, "How can we effectively manage thousands of servers and tens of thousands of users?" In some instances, the solution lies in the employment of specialized software packagesbut in the vast majority of the cases, the solution is a simple VBScript. In Microsoft Windows Server 2003, enterprise manageability was one of the design goals, and VBScript is one path to unlocking the rich storehouse of newly added features. Using the techniques outlined in Microsoft VBScript Step by Step, anyone can begin crafting custom scripts within minutes of opening these pages. I'm not talking about the traditional Hello World scriptI'm talking about truly useful scripts that save time and help to ensure accurate and predictable results. Whereas in the past scripting was somewhat hard to do, required special installations of various implementations, and was rather limited in its effect, with the release of Microsoft Windows XP, Windows Server 2003, and Windows Vista, scripting is coming into its own. This is really as it should be. However, most administrators and IT professionals do not have an understanding of scripting because in the past scripting was not a powerful alternative for platform management. However, in a large enterprise, it is a vital reality that one simply cannot perform management from the GUI applications because it is too time-constraining, too error prone, and, after a while, too irritating. Clearly there needs to be a better way, and there is. Scripting is the answer. A Practical Approach to ScriptingMicrosoft VBScript Step by Step will equip you with the tools to automate setup, deployment, and management of Microsoft Windows 2003 networks via the various scripting interfaces contained within the product. In addition, it will provide you with an understanding of a select number of VBScripts adaptable to your own unique environments. This will lead you into an awareness of the basics of programming through modeling of fundamental techniques. The approach I take to teaching you how to use VBScript to automate your Windows 2003 servers is similar to the approach used in some executive foreign language schools. You'll learn by using the language. In addition, concepts are presented not in a dry academic fashion, but in a dynamic, real-life manner. When a concept is needed to accomplish something, it is presented. If a topic is not useful for automating network management, I don't bring it forward. This is a practical, application-oriented book, so the coverage of VBScript, Windows Scripting Host, Active Directory Service Interfaces (ADSI), and Windows Management Instrumentation (WMI) is not exceedingly deep. This is not a reference book; it is a tutorial, a guidea spring-board for ideas, perhapsbut not an encyclopedia. Is This Book for Me?Microsoft VBScript Step by Step is aimed at several audiences, including:
Outline of This BookThis book is divided into four parts, each covering a major facet of scripting. The following sections describe these parts. Part I: Covering the BasicsOkay, so you've decided you need to learn scripting. Where do you begin? Start here in Part I! In Chapter 1, "Starting From Scratch," you learn the basics: what a script is, how to read it, and how to write it. Once you move beyond using a script to figure out what your IP address is and print it to a file, you need to introduce some logic into the script, which you do in Chapter 2 through Chapter 5. You'll learn how to introduce conditions and add some intelligence to allow the script to check some stuff, and then based upon what it finds, do some other stuff. This section concludes by looking at troubleshooting scripts. I've made some mistakes that you don't need to repeat! Here are the chapters in Part I:
Part II: Basic Windows AdministrationIn Part II, you dig deep into VBScript and WMI and really begin to see the power you can bring to your automation tasks. In working with the file system, you see how to use the file system object to create files, delete files, and verify the existence of files. All these basic tasks provide loads of flexibility for your scripts. Next, you move on to working with folders, learning how to use VBScript to completely automate the creation of folders and files on your servers and users' workstations. In the last half of Part II, you get an in-depth look at the power of WMI when it is combined with the simplicity and flexibility of VBScript. Here are the chapters in Part II:
Part III: Advanced Windows AdministrationThis section will shave at least four points off your golf handicap because you'll get to play an extra 18 holes a week due to the time you'll save! At least three things are really painful when it comes to administering Windows servers: all those click, click, and save motions; all the time spent waiting for the screen to refresh; and loosing your place in a long list of users. Guess what? In this section, some of that pain is relieved. When Human Resources hires 100 people, you tell them to send you a spreadsheet with the new users, and then use a script to create those users. It takes 2 minutes instead of 2 hours. (Dude, that's the front nine!) In addition to saving time, scripting your administrative tasks reduces the likelihood of errors. If you have to set a particular set of access control lists on dozens of folders, a script is the only way to ensure all the flags are set correctly. Here are the chapters in Part III:
Part IV: Scripting Other ApplicationsOnce you learn how to use WMI and VBScript to automate Windows Server 2003, the logical question is, "What else can I do?" Well, with the latest version of Microsoft Exchange and Internet Information Services (IIS), the answer is, "Quite a lot." So in this part of the book, you look at using WMI and VBScript to automate other applications. In IIS 6.0, nearly everything that can be configured via GUI tools can also be scripted. This enables the Web administrator to simplify management and to also ensure repeatable configuration of the Web sites from a security perspective. In Exchange administration, many routine tasks can be simplified by using VBScript. In Part IV, you look at how to leverage the power of VBScript to simplify user management, to configure and administer Exchange, and to troubleshoot some of the common issues confronting the enterprise Exchange administrator. The chapters in Part IV are as follows:
Part V: AppendicesThe appendices in this book are not the normal "never read" stuff. Indeed, you will find yourself referring again and again to these five crucial documents. In Appendix A you will find lots of ideas for further work in developing your mastery of VBScript. Appendix B will save you many hours of searching for the "special names" that unlock the power of ADSI scripting. Appendix C helps you find the special WMI namespaces that enable you to perform many cool "tricks" in your scripting. And last but certainly not least is Appendix D, which contains my documentation "cheat sheet." Actually, you will want to read it rather early in your scripting career. Appendix E contains the Special Folder Constants, which, as you will see in the very first script in the book, can provide easy access to some of the most vital folders on your workstation!
Finding Your Best Starting PointThis book will help you add essential skills for using VBScript to automate your Windows environment. You can use this book if you are new to scripting, new to programming, or switching from another scripting language. The following table will assist you in picking the best starting point in the book.
About the Companion CDThe CD accompanying this book contains additional information and software components, including the following files:
Installing the Practice Files on Your ComputerFollow these steps to install the practice files on your computer so that you can use them with the exercises in this book. The code samples are installed to the following location on your computer: My Documents\Microsoft Press\VBScriptSBS\ Uninstalling the Practice FilesFollow these steps to remove the practice files from your computer.
System Requirements
Technical SupportEvery effort has been made to ensure the accuracy of this book and the contents of the companion CD-ROM. Microsoft Press provides corrections for books through the World Wide Web at http://www.microsoft.com/learning/support. To connect directly with the Microsoft Press Knowledge Base and enter a query regarding a question or an issue that you might have, go to http://www.microsoft.com/learning/support/search.asp. If you have comments, questions, or ideas regarding this book or the companion CD-ROM, please send them to Microsoft Press using either of the following methods: E-mail: Postal Mail: Microsoft Press Please note that product support is not offered through the preceding addresses. For additional support information regarding this book and the CD-ROM (including answers to commonly asked questions about installation and use), visit the Microsoft Press Technical Support Web site at www.microsoft.com/learning/support/books/. For support information regarding Microsoft software, please connect to http://support.microsoft.com. |