Advanced Vbscript for Microsoft Windows Administrators Ebook
Total Page:16
File Type:pdf, Size:1020Kb
6-2244-2eBookFM.book Page 1 Thursday, December 15, 2005 5:22 PM 6-2244-2eBookFM.book Page ii Thursday, December 15, 2005 5:22 PM PUBLISHED BY Microsoft Press A Division of Microsoft Corporation One Microsoft Way Redmond, Washington 98052-6399 Copyright © 2006 by Don Jones and Jeffery Hicks All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher. Library of Congress Control Number 2005937886 Printed and bound in the United States of America. 1 2 3 4 5 6 7 8 9 QWT 9 8 7 6 5 Distributed in Canada by H.B. Fenn and Company Ltd. A CIP catalogue record for this book is available from the British Library. Microsoft Press books are available through booksellers and distributors worldwide. For further information about international editions, contact your local Microsoft Corporation office or contact Microsoft Press Inter- national directly at fax (425) 936-7329. Visit our Web site at www.microsoft.com/mspress. Send comments to [email protected]. Microsoft, Active Directory, ActiveX, Excel, FrontPage, JScript, Microsoft Press, MSDN, Tahoma, Verdana, Visio, Visual Basic, Win32, Windows, the Windows logo, Windows NT, and Windows Server are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. Other product and company names mentioned herein may be the trademarks of their respective owners. The example companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events depicted herein are fictitious. No association with any real company, organization, product, domain name, e-mail address, logo, person, place, or event is intended or should be inferred. This book expresses the author’s views and opinions. The information contained in this book is provided with- out any express, statutory, or implied warranties. Neither the authors, Microsoft Corporation, nor its resellers, or distributors will be held liable for any damages caused or alleged to be caused either directly or indirectly by this book. Acquisitions Editor: Martin DelRe Project Editor: Melissa von Tschudi-Sutton Production: OTSI Body Part No. X11-89440 6-2244-2eBookFM.book Page iii Thursday, December 15, 2005 5:22 PM Contents at a Glance Part I The Basics of Advanced Windows Scripting 1 Getting Started. .3 2 Script Security. 41 Part II Packaging Your Scripts 3 Windows Script Files . 57 4 Windows Script Components. 95 5 HTML Applications: Scripts with a User Interface. 125 Part III The Basics of Advanced Windows Scripting 6 Remote Scripting . 161 7 Database Scripting. 179 8 Advanced ADSI and LDAP Scripting . 207 9 Using ADO and ADSI Together . 245 10 Advanced WMI Scripting . 261 11 WMI Events . 285 12 Better Scripting with WMI Tools . 319 13 Advanced Scripting in Windows XP and Windows Server 2003. 353 Part IV Scripting for the Enterprise 14 Group Policy Management Scripting . 393 15 Exchange 2003 Scripting. 425 16 Microsoft Operations Manager 2005 Scripting. 463 17 Virtual Server 2005 Scripting . 483 Part V Appendix Advanced Script Editor Features . 505 iii 6-2244-2eBookFM.book Page iv Thursday, December 15, 2005 5:22 PM iv Table of Contents 6-2244-2eBookFM.book Page v Thursday, December 15, 2005 5:22 PM Table of Contents Acknowledgements . xiii Introduction . .xv Part I The Basics of Advanced Windows Scripting 1 Getting Started. .3 Prerequisite Knowledge. 3 Understanding Windows Script Host Basics. 4 Using the FileSystemObject Library . 15 Understanding Arrays . 22 Understanding Active Directory Services Interface Fundamentals . 24 Understanding Windows Management Instrumentation Fundamentals . 29 Advanced Scripting Goals . 34 Securing Your Scripts . 34 Creating Your Own Script Components and Libraries . 34 Running Scripts Remotely . 35 Retrieving Information from Active Directory . 35 Manipulating Information Stored in a Database. 35 Managing Your Windows Environment with WMI Events . 35 Using New WMI Classes with Windows XP and Windows Server 2003 . 35 Managing Group Policy Objects with Scripting. 35 Managing Your Exchange 2003 Environment . 36 Incorporating Your Scripts into Microsoft Operations Manager . 36 Creating a Visual Interface for Your Script with Internet Explorer and . 36 HTML Applications (HTAs) What We Won’t Cover . 36 Finding Information about JScript, Perl, Python, and KiXtart . 37 The Right Tool for the Job. 38 Scripting Techniques . 39 Summary . 39 2 Script Security. 41 Script Encoding and Decoding. 41 v 6-2244-2eBookFM.book Page vi Thursday, December 15, 2005 5:22 PM vi Table of Contents Script Signing and the Windows Script Host TrustPolicy . 43 Understanding Digital Certificates and Script Signing . 43 Understanding WSH TrustPolicy . 46 Configuring WSH TrustPolicy in Your Environment . 47 Signing Scripts by Using a Digital Certificate . 49 Using Software Restriction Policies . 52 Alternate Credentials . 52 Using the RunAs Command . 52 Using Scheduled Tasks Credentials . 53 Using ADSI Alternate Credentials . 53 Using WMI Alternate Credentials . 54 Summary . 54 Part II Packaging Your Scripts 3 Windows Script Files . 57 Defining Windows Script Files . 57 Understanding XML. 58 The package Tag . 59 The comment Tag . 59 The job Tag . 59 The runtime Tag . 60 The description Tag . 60 The example Tag . 60 The named Tag . 61 The object Tag . 61 The script Tag . 62 Creating Script Jobs. 63 Including Other Scripts . 63 Adding Resources . ..