Windows Command-Line Administrator's Pocket Consultant .

Transcription

PUBLISHED BYMicrosoft PressA Division of Microsoft CorporationOne Microsoft WayRedmond, Washington 98052-6399Copyright 2008 by William R. StanekAll rights reserved. No part of the contents of this book may be reproduced or transmitted in anyform or by any means without the written permission of the publisher.Library of Congress Control Number: 2008927283Printed and bound in the United States of America.1 2 3 4 5 6 7 8 9 QWE 3 2 1 0 9 8Distributed 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 furtherinformation about international editions, contact your local Microsoft Corporation office orcontact Microsoft Press International directly at fax (425) 936-7329. Visit our Web site atwww.microsoft.com/mspress. Send comments to mspinput@microsoft.com.Microsoft, Microsoft Press, Access, Active Directory, BitLocker, Hyper-V, Internet Explorer, MS-DOS,SharePoint, SQL Server, Win32, Windows, Windows Media, Windows NT, Windows PowerShell,Windows Server, and Windows Vista are either registered trademarks or trademarks of MicrosoftCorporation in the United States and/or other countries. Other product and company namesmentioned 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 orshould be inferred.This book expresses the author's views and opinions. The information contained in this book isprovided without any express, statutory, or implied warranties. Neither the authors, MicrosoftCorporation, nor its resellers, or distributors will be held liable for any damages caused or allegedto be caused either directly or indirectly by this book.Acquisitions Editor: Martin DelReDevelopmental Editor: Karen SzallProject Editor: Maria GargiuloEditorial Production: ICC Macmillan, Inc.Technical Reviewer: James Johnson, Technical Review services provided by Content Master,a member of CM Group, LtdCover: Tom Draper DesignBody Part No. X14-71538

Contents at a GlancePart IWindows Command-Line Fundamentals1Overview of the Windows Command Line. . . . . . . . . . . . . . . . . . . . . . 32Getting the Most from the Command Line . . . . . . . . . . . . . . . . . . . . 173Command-Line Scripting Essentials . . . . . . . . . . . . . . . . . . . . . . . . . . 27Part II Windows Systems Administration Using theCommand Line4Deploying Windows Servers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 595Managing Windows Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 796Event Logging, Tracking, and Monitoring . . . . . . . . . . . . . . . . . . . . 1057Monitoring Processes and Maintaining Performance . . . . . . . . . . 1258Managing Event and Performance Logging . . . . . . . . . . . . . . . . . . 1539Scheduling Tasks to Run Automatically . . . . . . . . . . . . . . . . . . . . . . 191Part III Windows File System and Disk AdministrationUsing the Command Line10Configuring and Maintaining Disks . . . . . . . . . . . . . . . . . . . . . . . . . 22511Partitioning Basic Disks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25712Managing Volumes and RAID on Dynamic Disks . . . . . . . . . . . . . . 279Part IV Windows Active Directory Administration Usingthe Command Line13Core Active Directory Services Administration . . . . . . . . . . . . . . . . 29714Managing Computer Accounts and Domain Controllers . . . . . . . 31515Managing Active Directory Users and Groups . . . . . . . . . . . . . . . . 339Part V Windows Network Administration Using theCommand Line16Administering Network Printers and Print Services . . . . . . . . . . . . 37117Configuring, Maintaining, and TroubleshootingTCP/IP Networking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405iii

ivContents at a GlanceAppendix A Essential Command-Line Tools Reference . . . . . . . . . . . . . . . . 453Appendix BQuick Reference for Netsh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501

Table of ContentsAcknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xviiIntroduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xixWho Is This Book For? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xixHow Is This Book Organized? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxConventions Used in This Book. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xxiSupport . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiiPart IWindows Command-Line Fundamentals1 Overview of the Windows Command Line . . . . . . . . . . . . . . . . . . 3Command Line Essentials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3Understanding the Windows Command Shell . . . . . . . . . . . . . . . . 4Understanding the MS-DOS Command Shell . . . . . . . . . . . . . . . . 8Understanding Windows PowerShell. . . . . . . . . . . . . . . . . . . . . . . . 9Configuring Command-Line Properties . . . . . . . . . . . . . . . . . . . . 11Working with the Command History. . . . . . . . . . . . . . . . . . . . . . . 12Making Supplemental Components Available . . . . . . . . . . . . . . . . . . . 13Using the Microsoft Remote Server AdministrationTools for Windows Vista . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14Registering the Remote Server AdministrationTools Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14Configuring and Selecting Remote ServerAdministration Tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15Removing the Remote Server Administration Tools . . . . . . . . . . 16Removing the Remote Server Administration Tools Package . . 162Getting the Most from the Command Line . . . . . . . . . . . . . . . . . . . . 17Managing Command Shell Startup . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18Working with the Command Path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20Managing the Command Path . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20Managing File Extensions and File Associations . . . . . . . . . . . . . 21What do you think of this book? We want to hear from you!Microsoft is interested in hearing your feedback so we can continually improve our booksand learning resources for you. To participate in a brief survey, please visit:www.microsoft.com/learning/booksurveyv

viTable of ContentsRedirecting Standard Input, Output, and Error . . . . . . . . . . . . . . . . . . 22Redirecting Standard Output to Other Commands . . . . . . . . . . 23Redirecting I/O to and from Files. . . . . . . . . . . . . . . . . . . . . . . . . . 24Redirecting Standard Error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24Chaining and Grouping Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . 25Using Chains of Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25Grouping Command Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . 263Command-Line Scripting Essentials. . . . . . . . . . . . . . . . . . . . . . . . . . . 27Creating Command-Line Scripts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27Common Statements and Commands for Scripts . . . . . . . . . . . . . . . . 29Clearing the Command-Shell Window . . . . . . . . . . . . . . . . . . . . . 29Adding Comments to Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30Managing Text Display and Command Echoing . . . . . . . . . . . . . 31Fine-Tuning Command Echo with @ . . . . . . . . . . . . . . . . . . . . . . 32Setting the Console Window Title and Colors . . . . . . . . . . . . . . . 33Passing Arguments to Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34Getting Acquainted with Variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35Using Variables in Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36Naming Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36Setting Variable Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37Substituting Variable Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38Localizing Variable Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40Using Mathematical Expressions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41Working with Arithmetic and Assignment Operators. . . . . . . . . 41Understanding Operator Precedence . . . . . . . . . . . . . . . . . . . . . . 42Simulating Exponents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43Command-Line Selection Statements . . . . . . . . . . . . . . . . . . . . . . . . . . 43Using If . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43Using If Not . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44Using If Defined and If Not Defined . . . . . . . . . . . . . . . . . . . . . . . 45Nesting Ifs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45Making Comparisons in If Statements. . . . . . . . . . . . . . . . . . . . . . 45Command Line Iteration Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . 46Iteration Essentials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47Stepping Through a Series of Values . . . . . . . . . . . . . . . . . . . . . . . 48Iterating Through Groups of Files . . . . . . . . . . . . . . . . . . . . . . . . . 49Iterating Through Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49Parsing File Content and Output . . . . . . . . . . . . . . . . . . . . . . . . . . 51

Table of ContentsviiCreating Subroutines and Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . 54Using Subroutines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54Using Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56Part II Windows Systems Administration Using theCommand Line4Deploying Windows Servers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59Managing Server Configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59Working with Roles, Role Services, and Features . . . . . . . . . . . . . . . . . 61Managing Roles, Role Services, and Features . . . . . . . . . . . . . . . . . . . . 68ServerManagerCmd Essentials . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68Querying Installed Roles, Role Services, and Features . . . . . . . . 74Installing Roles, Role Services, and Features . . . . . . . . . . . . . . . . . 75Removing Roles, Role Services, and Features . . . . . . . . . . . . . . . . 775Managing Windows Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79Examining System Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79Working with the Registry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81Understanding Registry Keys and Values . . . . . . . . . . . . . . . . . . . 82Querying Registry Values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84Comparing Registry Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85Saving and Restoring Registry Keys . . . . . . . . . . . . . . . . . . . . . . . . 86Adding Registry Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87Copying Registry Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87Deleting Registry Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88Exporting and Importing Registry Keys. . . . . . . . . . . . . . . . . . . . . 89Loading and Unloading Registry Keys . . . . . . . . . . . . . . . . . . . . . . 90Managing System Services. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92Viewing Configured Services. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92Starting, Stopping, and Pausing Services . . . . . . . . . . . . . . . . . . . 94Configuring Service Startup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95Configuring Service Logon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96Configuring Service Recovery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97Restarting and Shutting Down Systems from theCommand Line. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100Managing Restart and Shutdown of Local Systems. . . . . . . . . . 101Managing Restart and Shutdown of Remote Systems . . . . . . . 101Adding Shutdown or Restart Reasons and Comments . . . . . . . 102

viiiTable of Contents6Event Logging, Tracking, and Monitoring . . . . . . . . . . . . . . . . . . . . 105Windows Event Logging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105Viewing and Filtering Event Logs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109Viewing Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109Filtering Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110Writing Custom Events to the Event Logs . . . . . . . . . . . . . . . . . . . . . . 112Creating and Using Saved Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114Monitoring Performance: The Essentials . . . . . . . . . . . . . . . . . . . . . . . 117Understanding Performance Monitoring at theCommand Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118Tracking Performance Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1197Monitoring Processes and Maintaining Performance. . . . . . . . . . . 125Managing Applications, Processes, and Performance . . . . . . . . . . . . 125Understanding System and User Processes . . . . . . . . . . . . . . . . 125Examining Running Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . 127Monitoring System Resource Usage and Processes . . . . . . . . . 134Stopping Processes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142Detecting and Resolving Performance IssuesThrough Monitoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145Monitoring Memory Paging and Paging to Disk . . . . . . . . . . . 145Monitoring Memory Usage and the WorkingMemory Set for Individual Processes . . . . . . . . . . . . . . . . . . . . . 147Resolving Performance Bottlenecks. . . . . . . . . . . . . . . . . . . . . . . 1508Managing Event and Performance Logging. . . . . . . . . . . . . . . . . . . 153Managing the Event Logs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153Getting Started with Wevtutil . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153Listing Available Logs and Registered Publishers . . . . . . . . . . . 155Viewing and Changing Log Configuration. . . . . . . . . . . . . . . . . 157Exporting and Manipulating Event Logs . . . . . . . . . . . . . . . . . . 159Clearing Event Logs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164Centralizing Event Logging Across the Enterprise . . . . . . . . . . . . . . . 164Configuring Event Forwarding and Collection . . . . . . . . . . . . . 165Creating Subscriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166Managing Subscriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172Performance Logging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175Getting Started with Data Collector Sets . . . . . . . . . . . . . . . . . . 175Working with Data Collector Sets . . . . . . . . . . . . . . . . . . . . . . . . 176Collecting Performance Counter Data . . . . . . . . . . . . . . . . . . . . 178Configuring Performance Counter Alerts . . . . . . . . . . . . . . . . . . 183Viewing Data Collector Reports . . . . . . . . . . . . . . . . . . . . . . . . . . 187

Table of Contents9ixScheduling Tasks to Run Automatically . . . . . . . . . . . . . . . . . . . . . . 191Scheduling Tasks on Local and Remote Systems . . . . . . . . . . . . . . . . 191Introducing Task Scheduling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192Monitoring Scheduled Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196Scheduling Tasks with Task Scheduler . . . . . . . . . . . . . . . . . . . . . . . . . 198Creating Basic Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198Creating Advanced Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201Managing Task Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203Enabling and Disabling Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203Copying Tasks to Other Computers . . . . . . . . . . . . . . . . . . . . . . . 203Running Tasks Immediately . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204Removing Unwanted Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204Scheduling Tasks with Schtasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204Creating Scheduled Tasks with Schtasks /Create . . . . . . . . . . . . 204Creating Scheduled Tasks Triggered by Windows Events . . . . . 211Changing Scheduled Tasks with Schtasks /Change . . . . . . . . . . 213Querying for Configured Tasks with Schtasks /Query. . . . . . . . 216Creating Tasks Using XML Configuration Files . . . . . . . . . . . . . . 217Running Tasks Immediately with Schtasks /Run. . . . . . . . . . . . . 221Stopping Running Tasks with Schtasks /End . . . . . . . . . . . . . . . . 221Deleting Tasks with Schtasks /Delete . . . . . . . . . . . . . . . . . . . . . . 222Part III Windows File System and Disk Administration Usingthe Command Line10Configuring and Maintaining Disks . . . . . . . . . . . . . . . . . . . . . . . . . 225Getting Started with DiskPart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225DiskPart Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225DiskPart: An Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226Understanding Focus and What It Means. . . . . . . . . . . . . . . . . . 226DiskPart Commands and Scripts. . . . . . . . . . . . . . . . . . . . . . . . . . 227DiskPart: A Script Example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232Installing and Managing Hard Disk Drives . . . . . . . . . . . . . . . . . . . . . 234Installing and Checking for a New Drive. . . . . . . . . . . . . . . . . . . 235Checking Drive Status and Configuration . . . . . . . . . . . . . . . . . . 235Changing Drive Partition Styles . . . . . . . . . . . . . . . . . . . . . . . . . . 237Working with Basic and Dynamic Disks . . . . . . . . . . . . . . . . . . . . . . . . 239Understanding Basic and Dynamic Disks . . . . . . . . . . . . . . . . . . 239Setting the Active Partition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240Changing the Disk Type: Basic to Dynamic or Vice Versa. . . . . 241

xTable of ContentsMaintaining Disks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243Obtaining Disk Information and Managing FileSystems with FSUtil. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243Checking Disks for Errors and Bad Sectors . . . . . . . . . . . . . . . . . 246Fixing Disk Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249Controlling Auto Check on Startup . . . . . . . . . . . . . . . . . . . . . . . 250Defragmenting Disks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25211Partitioning Basic Disks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257Obtaining Partition Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257Creating Partitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258Creating Partitions for MBR Disks . . . . . . . . . . . . . . . . . . . . . . . . 258Creating Partitions for GPT Disks . . . . . . . . . . . . . . . . . . . . . . . . . 260Managing Drive Letters and Mount Points . . . . . . . . . . . . . . . . . . . . . 263Assigning Drive Letters or Mount Points . . . . . . . . . . . . . . . . . . 263Changing Drive Letters or Mount Points . . . . . . . . . . . . . . . . . . 264Removing Drive Letters or Mount Points . . . . . . . . . . . . . . . . . . 264Formatting Partitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265Using FORMAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266Using FILESYSTEMS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267Formatting: An Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270Managing Partitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271Converting a Partition or Volume to NTFS. . . . . . . . . . . . . . . . . 271Changing or Deleting the Volume Label . . . . . . . . . . . . . . . . . . 274Shrinking Partitions or Volumes . . . . . . . . . . . . . . . . . . . . . . . . . . 274Extending Partitions or Volumes . . . . . . . . . . . . . . . . . . . . . . . . . 276Deleting Partitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27612Managing Volumes and RAID on Dynamic Disks . . . . . . . . . . . . . . 279Obtaining Volume Information and Status . . . . . . . . . . . . . . . . . . . . . 279Creating and Managing Simple Volumes . . . . . . . . . . . . . . . . . . . . . . 282Creating Simple Volumes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282Extending Simple Volumes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283Bringing Dynamic Disks Online . . . . . . . . . . . . . . . . . . . . . . . . . . 284Deleting Volumes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285Providing Fault Tolerance with RAID on Dynamic Disks . . . . . . . . . . 285Implementing RAID-0: Disk Striping . . . . . . . . . . . . . . . . . . . . . . 286Implementing RAID-1: Disk Mirroring and Duplexing . . . . . . . 288Implementing RAID-5: Disk Striping with Parity . . . . . . . . . . . . 289Managing RAID and Recovering from Failure . . . . . . . . . . . . . . . . . . 291Breaking a Mirrored Set. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291

Table of ContentsxiResynchronizing and Repairing a Mirrored Set . . . . . . . . . . . . . 292Repairing a RAID-0 Striped Set Without Parity . . . . . . . . . . . . . 293Regenerating a RAID-5 Striped Set with Parity . . . . . . . . . . . . . 293Part IV Windows Active Directory Administration Using theCommand Line13Core Active Directory Services Administration . . . . . . . . . . . . . . . . 297Controlling Active Directory from the Command Line . . . . . . . . . . . 297Understanding Domains, Containers, and Objects . . . . . . . . . . 298Understanding Logical and Physical Structures inActive Directory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299Understanding Distinguished Names . . . . . . . . . . . . . . . . . . . . . 300Getting Started with the Active DirectoryCommand-Line Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301Making Directory Queries Using the DSQUERY Command . . . . . . . 302DSQUERY Subcommands and Syntax . . . . . . . . . . . . . . . . . . . . . 302Searching Using Names, Descriptions, and SAMAccount Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304Setting Logon and Run As Permissions for Searches. . . . . . . . . 306Setting the Start Node, Search Scope, and Object Limit . . . . . 307Setting the Output Format for Names . . . . . . . . . . . . . . . . . . . . 309Using DSQUERY with Other Active DirectoryCommand-Line Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311Searching for Problem User and Computer Accounts. . . . . . . . . . . . 311Renaming and Moving Objects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312Removing Objects from Active Directory . . . . . . . . . . . . . . . . . . . . . . 31314Managing Computer Accounts and Domain Controllers . . . . . . . 315Overview of Managing Computer Accounts from theCommand Line. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315Creating Computer Accounts in Active Directory Domains . . . . . . . 317Creating a Computer Account . . . . . . . . . . . . . . . . . . . . . . . . . . . 317Customizing Computer Account Attributes andGroup Memberships. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318Managing Computer Account Properties . . . . . . . . . . . . . . . . . . . . . . 319Viewing and Finding Computer Accounts . . . . . . . . . . . . . . . . . 319Setting or Changing a Computer’s Location orDescription Attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322Disabling and Enabling Computer Accounts . . . . . . . . . . . . . . . 322Resetting Locked Computer Accounts. . . . . . . . . . . . . . . . . . . . . 322Joining Computer Accounts to a Domain. . . . . . . . . . . . . . . . . . 324

xiiTable of ContentsRenaming Computers and Computer Accounts . . . . . . . . . . . . 326Moving Computer Accounts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327Deleting Computer Accounts . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327Working with Domain Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328Installing and Demoting Domain Controllers . . . . . . . . . . . . . . 328Finding Domain Controllers in Active Directory . . . . . . . . . . . . 328Designating Global Catalog Servers. . . . . . . . . . . . . . . . . . . . . . . . . . . 330Finding Global Catalog Servers . . . . . . . . . . . . . . . . . . . . . . . . . . 330Adding or Removing a Global Catalog . . . . . . . . . . . . . . . . . . . . 331Checking Caching Settings and GlobalCatalog Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331Designating Operations Masters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333Finding Operations Masters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333Configuring Operations Master Roles Using theCommand Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335Finding Read-Only Domain Controllers . . . . . . . . . . . . . . . . . . . . . . . 33715Managing Active Directory Users and Groups. . . . . . . . . . . . . . . . . 339Overview of Managing User Accounts from the Command Line . . 339Adding User Accounts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342Creating Domain User Accounts . . . . . . . . . . . . . . . . . . . . . . . . . 342Customizing Domain User Account Attributes andGroup Memberships . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344Creating Local User Accounts. . . . . . . . . . . . . . . . . . . . . . . . . . . . 345Managing User Accounts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347Viewing and Finding User Accounts . . . . . . . . . . . . . . . . . . . . . . 347Determining Group Membership for IndividualUser Accounts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349Setting or Changing User Account Attributes . . . . . . . . . . . . . . 350Disabling and Enabling User Accounts . . . . . . . . . . . . . . . . . . . . 351Resetting Expired User Accounts . . . . . . . . . . . . . . . . . . . . . . . . . 352Controlling and Resetting User Passwords . . . . . . . . . . . . . . . . . 352Moving User Accounts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353Renaming User Accounts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354Deleting User Accounts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355Overview of Managing Group Accounts from theCommand Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356Adding Group Accounts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357Creating Security and Distribution Groups. . . . . . . . . . . . . . . . . 357Creating a Local Group and Assigning Members . . . . . . . . . . . 360

Table of ContentsxiiiManaging Group Accounts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361Viewing and Finding Group Accounts . . . . . . . . . . . . . . . . . . . . . 361Determining Group Membership . . . . . . . . . . . . . . . . . . . . . . . . . 362Changing Group Type or Scope . . . . . . . . . . . . . . . . . . . . . . . . . . 363Adding, Removing, or Replacing Group Members . . . . . . . . . . 364Moving Group Accounts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366Renaming Group Accounts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367Deleting Group Accounts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368Part V Windows Network Administration Using theCommand Line16Administering Network Printers and Print Services . . . . . . . . . . . . 371Obtaining Support and Troubleshooting Informa

iii Contents at a Glance Part I Windows Command-Line Fundamentals 1 Overview of the Windows Command Line. . .