You are previewing Microsoft® Windows® Scripting Self-Paced Learning Guide.
O'Reilly logo
Microsoft® Windows® Scripting Self-Paced Learning Guide

Book Description

Get the inside track on how to write system administration scripts—straight from Microsoft scripting experts. This practical learning guide teaches how to use scripting techniques to gain control over your Microsoft Windows, Microsoft Internet Information Services (IIS), and Microsoft Exchange Server environments—all at your own pace. Build practical skills on everything from writing your first script in Microsoft Visual Basic® Scripting Edition (VBScript) to working with Windows Scripting Host (WSH), Windows Management Instrumentation (WMI), and Active Directory® Services Interface (ADSI), and from creating logon scripts to automating the management of systems, user accounts, files, printers, the registry, network services, directory services, security features, group policy, and more. The companion CD features the complete eBook, plus more than 200 sample scripts and a host of timesaving scripting tools.

Table of Contents

  1. Microsoft® Windows® Scripting Self-Paced Learning Guide
    1. SPECIAL OFFER: Upgrade this ebook with O’Reilly
    2. A Note Regarding Supplemental Files
    3. Acknowledgments
    4. About This Book
      1. A Practical Approach to Scripting
      2. Is This Book for Me?
      3. Outline of This Book
        1. Part 1: Covering the Basics
        2. Part 2: Basic Windows Administration
        3. Part 3: Advanced Windows Administration
        4. Part 4: Scripting Other Applications
        5. Part 5: Appendices
      4. About the Companion CD
      5. System Requirements
        1. Technical Support
    5. 1. Covering the Basics
      1. 1. Starting from Scratch
        1. Before You Begin
        2. Running Your First Script
          1. Header Information
            1. Option Explicit
            2. On Error Resume Next
            3. Dim
          2. Reference Information
          3. Worker Information
          4. Output Information
        3. Enhancing Your Script
          1. Docs That Make House Calls
        4. Modifying an Existing Script
          1. Modifying the Header Information
          2. Modifying the Reference Information
          3. Modifying the Worker Information
          4. Modifying the Output information
        5. Summary
        6. Quiz Yourself
        7. On Your Own: Lab 1 Exploring a VBScript
          1. Lab Instructions
        8. Lab 2 Customizing an Existing Script
          1. Scenario
          2. Lab Instructions
      2. 2. Getting in the Loop
        1. Before You Begin
        2. Adding Power to Scripts
        3. For Each...Next
          1. Header Information
            1. Defining Constants
            2. Constants vs. Variables
            3. Shared Benefits of Constants and Variables
            4. Collections
          2. Reference Information
          3. Worker Information
        4. For...Next
          1. Header Information
          2. Reference Information
          3. Worker and Output Information
        5. Do While...Loop
          1. Header Information
          2. Reference Information
          3. Worker and Output Information
        6. Do Until...Loop
          1. Worker and Output Information
        7. Summary
        8. Quiz Yourself
        9. On Your Own: Lab 3 Using the For Each...Next Command
          1. Lab Instructions
        10. Lab 4 Modifying the Ping Script
          1. Lab Instructions
      3. 3. Adding Intelligence
        1. Before You Begin
        2. If...Then
          1. Header Information
          2. Reference Information
          3. Worker and Output Information
          4. Intrinsic Constants
        3. If...Then...ElseIf
          1. Header Information
          2. Reference Information
          3. Worker and Output Information
        4. If...Then...Else
        5. Select Case
          1. Header Information
          2. Reference Information
          3. Worker and Output Information
        6. Summary
        7. Quiz Yourself
        8. On Your Own: Lab 5 Modifying CPUType.vbs
          1. Lab Instructions
        9. Lab 6 Modifying ComputerRoles.vbs
          1. Scenario
            1. Part A
            2. Part B
      4. 4. The Power of Many
        1. Before You Begin
        2. Passing Arguments
        3. Command-Line Arguments
          1. Making the Change
          2. Running from the Command Prompt
          3. No Arguments?
          4. Creating a Useful Error Message
        4. Using Multiple Arguments
          1. Header Information
          2. Reference Information
          3. Worker and Output Information
        5. Tell Me Your Name
          1. Reasons for Named Arguments
          2. Making the Change to Named Arguments
          3. Running a Script with Named Arguments
        6. Working with Arrays
        7. Moving Past Lame Arrays
          1. Header Information
          2. Reference Information
          3. Worker and Output Information
          4. What Does UBound Mean?
        8. Two-Dimensional Arrays
          1. Mechanics of Two-Dimensional Arrays
          2. Header Information
          3. Reference Information
          4. Worker and Output Information
            1. Using the For...Next Construction
            2. Assigning Values to Each Element
        9. Summary
        10. Quiz Yourself
        11. On Your Own: Lab 7 Working with Passing Arguments
          1. Lab Instructions
        12. Lab 8 Building Arrays
          1. Lab Instructions
        13. Lab 9 Modifying a Script
          1. Lab Instructions
      5. 5. The Power of Many More
        1. Before you Begin
        2. Strings and Arrays
        3. Parsing Passed Text into an Array
          1. Header Information
          2. Reference Information
          3. Worker Information
          4. Output Information
        4. Parsing Passed Text
          1. Header Information
          2. Reference Information
          3. Worker Information
          4. Output Information
        5. Working with Dictionaries
          1. Using the Dictionary
            1. Compare Mode
          2. Adding Items to the Dictionary
        6. Summary
        7. Quiz Yourself
        8. Own Your Own: Lab 10a Implementing Basics for the InStr Command
          1. Lab Instructions
        9. Lab 10b Understanding Advanced Features of the InStr Command
          1. Lab Instructions
        10. Lab 11 Creating a Dictionary
          1. Lab Instructions
    6. 2. Basic Windows Administration
      1. 6. Working with the File System
        1. Before You Begin
        2. Creating File System Object
        3. File It Under Files
          1. Header Information
          2. Reference Information
          3. Worker and Output Information
        4. File Properties
        5. File Attributes
          1. Implementing the Attributes Property
          2. Setting File Attributes
        6. A File, a File, I Need to Create a File
        7. Writing to a Text File
          1. How Shall I Write Thee? Let Me Count the Ways...
          2. Overwriting a File
        8. Existential File Approaches
        9. Summary
        10. Quiz Yourself
        11. On Your Own: Lab 12 Creating Files
        12. Lab 13 Creating a Log File
      2. 7. Fun with Folders
        1. Before You Begin
        2. Working with Folders
          1. Creating the Basic Folder
          2. Header Information
          3. Reference Information
          4. Worker Information
          5. Output Information
        3. Automatic Cleanup
          1. Deleting a Folder
          2. Deleting Multiple Folders
        4. Binding to Folders
          1. Does the Folder Exist?
        5. Copying Folders
        6. Moving On Up
        7. Summary
        8. Quiz Yourself
        9. On Your Own: Lab 14 Creating Folders
        10. Lab 15 Deleting Folders
      3. 8. Why Windows Management Instrumentation?
        1. Before You Begin
        2. What Is WMI?
          1. An Object in Any Other Namespace...
          2. More Than Just a Name
        3. Providers
        4. Adding a Touch of Class
        5. Querying WMI
          1. Header Information
          2. Reference Information
          3. Worker and Output Information
        6. Summary
        7. Quiz Yourself
        8. On Your Own: Lab 16 Retrieving Hotfix Information
          1. Lab Instructions
        9. Lab 17 Echoing the Time Zone
          1. Lab Instructions
      4. 9. WMI Continued
        1. Before You Begin
        2. Alternate Ways of Configuring the WMI Moniker
        3. Accepting Defaults
          1. Reference Information
          2. Worker and Output Information
            1. Working with Multivalue Properties
        4. Moniker Security Settings
          1. WbemPrivilege Has Its Privileges
        5. Summary
        6. Quiz Yourself
        7. On Your Own: Lab 18a Using the Default WMI Moniker
          1. Lab Instructions
        8. Lab 18b Invoking the WMI Moniker to Display the Machine Boot Configuration
          1. Lab Instructions
        9. Lab 18c Including Additional Security Permissions
          1. Lab Instructions
        10. Lab 19 Using Win32_Environment and VBScript to Learn About WMI
          1. Lab Instructions
      5. 10. Using WMI Queries
        1. Before you Begin
        2. Tell Me Everything About Everything!
        3. Next
          1. Header information
          2. Reference Information
        4. Worker and Output Information
        5. Selective Data from All Instances
        6. Selecting Multiple Properties
        7. Specifying Specifics
        8. Smooth Operator
        9. Where Is the Where Clause?
        10. Summary
        11. Quiz Yourself
        12. On Your Own: Lab 20 Writing an Informative WMI Script
          1. Lab Instructions
        13. Lab 21a Obtaining More Direct Information
          1. Lab Instructions
        14. Lab 21b Using a More Complicated Where Clause
          1. Lab Instructions
    7. 3. Advanced Windows Administration
      1. 11. Introduction to Active Directory Service Interfaces
        1. Before you Begin
        2. Working with ADSI
          1. Reference Information
          2. ADSI Providers
          3. LDAP Names
          4. Worker Information
            1. IADsContainer
            2. Binding
        3. Output Information
        4. Creating Users
          1. Reference Information
          2. Worker Information
          3. Output Information
        5. Summary
        6. Quiz Yourself
        7. On Your Own: Lab 22 Creating OUs
          1. Lab Instructions
        8. Lab 23 Creating Multi-Valued Users
          1. Lab Instructions
      2. 12. Reading and Writing for ADSI
        1. Before You Begin
        2. Working with Users
          1. General User Information
          2. Reference Information
          3. Worker Information
          4. Output Information
        3. Creating the Second Page
          1. Reference Information
          2. Worker Information
            1. Staying Put
          3. Output Information
        4. Deleting Users
        5. Summary
        6. Quiz Yourself
        7. On Your Own: Lab 24 Deleting Users
          1. Lab Instructions
        8. Lab 25 Using the Event Log
          1. Lab Instructions
      3. 13. Searching Active Directory
        1. Before You Begin
        2. Connecting to Active Directory to Perform a Search
          1. Header Information
          2. Reference Information
          3. Worker and Output Information
        3. Creating More Effective Queries
        4. Searching for Specific Types of Objects
          1. Reference Information
          2. Output Information
        5. What is Global Catalog?
        6. Summary
        7. Quiz Yourself
        8. On Your Own: Lab 26 Creating an ADO Query into Active Directory
          1. Lab Instructions
        9. Lab 27 Controlling How a Script Executes Against Active Directory
          1. Lab Instructions
      4. 14. Configuring Networking Components
        1. Before You Begin
        2. WMI and the Network
          1. Making the Connection
          2. Header Information
          3. Reference Information
          4. Worker and Output Information
        3. Changing the TCP/IP Settings
          1. Header Information
          2. Reference Information
          3. Worker and Output Information
        4. Merging WMI and ADSI
        5. Win32_NetworkAdapterConfiguration
        6. Summary
        7. Quiz Yourself
        8. On Your Own: Lab 28 Using WMI to Assign Network Settings
          1. Lab Instructions
        9. Lab 29 Combining WMI and ADSI in a Script
          1. Lab Instructions
      5. 15. Subs and Other Round Things
        1. Before You Begin
        2. Working with Subroutines
          1. Calling the Subroutine
          2. Creating the Subroutine
        3. Creating Users and Logging Results
          1. Header Information
          2. Reference Information
          3. Worker Information
          4. Output Information
        4. Summary
        5. Quiz Yourself
        6. On Your Own: Lab 30 Using ADSI and Subs, and Creating Users
          1. Lab Instructions
        7. Lab 31 Adding a Logging Subroutine
          1. Lab Instructions
      6. 16. Logon Scripts
        1. Before You Begin
        2. Working with IADsADSystemInfo
        3. Using Logon Scripts
        4. Deploying Logon Scripts
          1. Header Information
          2. Reference Information
            1. Using the WshNetwork Class
            2. Using the Join Function
          3. Worker Information
        5. Output Information
        6. Summary
        7. Quiz Yourself
        8. On Your Own: Lab 32 Adding a Group to a Logon Script
          1. Lab Instructions
        9. Lab 33 Adding Logging to a Logon Script
          1. Lab Instructions
      7. 17. Working with the Registry
        1. Before You Begin
        2. First You Back Up
        3. Creating the WshShell Object
          1. Setting the comspec Variable
          2. Defining the Command Line
        4. Connecting to the Registry
          1. Header Information
          2. Reference Information
          3. Worker and Output Information
        5. Unleashing StdRegProv
        6. Creating Registry Keys
          1. Header Information
          2. Reference Information
          3. Worker and Output Information
        7. Writing to the Registry
        8. Deleting Registry Information
        9. Summary
        10. Quiz Yourself
        11. On Your Own: Lab 34 Reading the Registry Using WMI
          1. Lab Instructions
        12. Lab 35 Creating Registry Keys
          1. Lab Instructions
      8. 18. Working with Printers
        1. Before You Begin
        2. Working with Win32_Printer
        3. Obtaining the Status of Printers
          1. Header Information
          2. Reference Information
          3. Worker Information
          4. Output Information
        4. Creating a Filtered Print Monitor
          1. Reference Information
          2. Output Information
        5. Monitoring Print Queues
          1. Worker and Output Information
        6. Summary
        7. Quiz Yourself
        8. On Your Own: Lab 36 Monitoring Print Jobs
          1. Lab Instructions
        9. Lab 37 Checking the Status of a Print Server
          1. Lab Instructions
    8. 4. Scripting Other Applications
      1. 19. Managing IIS 6.0
        1. Before You Begin
        2. What’s in a Name?
          1. CIM_ManagedSystemElement
          2. CIM_Setting
          3. IIsStructuredDataClass
          4. CIM_Component
          5. CIM_ElementSetting
          6. Using MicrosoftIISv2
        3. Making the Connection
          1. Header Information
          2. Reference Information
          3. Worker and Output Information
        4. Creating a Website
          1. Header Information
          2. Reference Information
          3. Worker and Output Information
        5. Summary
        6. Quiz Yourself
        7. On Your Own: Lab 38 Backing Up the Metabase
          1. Lab Instructions
        8. Lab 39 Importing the Metabase
          1. Lab Instructions
      2. 20. Working with Exchange 2003
        1. Before You Begin
        2. Working with the Exchange Provider
        3. Connecting to MicrosoftExchangeV2
          1. The Exchange_QueueSMTPVirtualServer Class
          2. Header Information
          3. Reference Information
          4. Worker Information
          5. Output Information
        4. Exchange Public Folders
        5. Exchange_FolderTree
        6. Summary
        7. Quiz Yourself
        8. On Your Own: Lab 40 Using the Exchange_Logon Class
          1. Lab Instructions
        9. Lab 41 Using the Exchange_Mailbox Class
          1. Lab Instructions
    9. 5. Appendices
      1. A. VBScript Documentation
        1. Constants
        2. VBScript Run-Time Errors
        3. VBScript Syntax Errors
      2. B. ADSI Documentation
        1. Computer Object Mapping
        2. Domain Object User Interface Mapping
        3. Group Object User Interface Mapping
        4. Object Property Sheet
        5. Organizational Unit User Interface Mapping
        6. Printer Object User Interface Mapping
        7. Shared Folder Object User Interface Mapping
        8. User Object User Interface Mapping
      3. C. WMI Documentation
        1. Win32 Classes
        2. WMI Providers
        3. WMI Scripting API Objects
        4. WMI Log Files
      4. D. Documentation Standards
        1. Header Information Section
        2. Reference Information Section
        3. Worker Information Section
        4. Sample of Documentation Use
    10. E. About the Author
    11. Index
    12. SPECIAL OFFER: Upgrade this ebook with O’Reilly