ESSENTIAL POWERSHELL Holger

ESSENTIAL POWERSHELL Holger

ESSENTIAL POWERSHELL This page intentionally left blank ESSENTIAL POWERSHELL Holger Schwichtenberg Upper Saddle River, NJ • Boston • Indianapolis • San Francisco New York • Toronto • Montreal • London • Munich • Paris • Madrid Cape Town • Sydney • Tokyo • Singapore • Mexico City Many of the designations used by manufacturers and sellers to distinguish their products are Editor-in-Chief claimed as trademarks. Where those designations appear in this book, and the publisher was Karen Gettman aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals. Executive Editor Neil Rowe The author and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability Development is assumed for incidental or consequential damages in connection with or arising out of the use of Editor the information or programs contained herein. Mark Renfrow The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases Managing Editor or special sales, which may include electronic versions and/or custom covers and content partic- Kristy Hart ular to your business, training goals, marketing focus, and branding interests. For more informa- tion, please contact: Project Editor U.S. Corporate and Government Sales Betsy Harris (800) 382-3419 Copy Editor [email protected] Keith Cline For sales outside the United States please contact: Indexer International Sales Publishing Works, [email protected] Inc. Visit us on the Web: www.informit.com/aw Proofreader Library of Congress Cataloging-in-Publication Data Paula Lowell Schwichtenberg, Holger. Technical Editor Essential PowerShell / Holger Schwichtenberg. Tony Bradley p. cm. ISBN 978-0-672-32966-1 Publishing 1. Windows PowerShell (Computer programming language) 2. Command languages Coordinator (Computer science) 3. Scripting languages (Computer science) 4. Systems programming Cindy Teeters (Computer science) 5. Microsoft Windows (Computer file) I. Title. QA76.73.W56S39 2008 Cover Designer 005.4’2—dc22 Gary Adair 2008020010 Compositor Copyright © 2008 by Pearson Education, Inc. Nonie Ratcliff All rights reserved. Printed in the United States of America. This publication is protected by copy- right, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechani- cal, photocopying, recording, or likewise. For information regarding permissions, write to: Pearson Education, Inc Rights and Contracts Department 501 Boylston Street, Suite 900 Boston, MA 02116 Fax (617) 671 3447 ISBN-13: 978-0-672-32966-1 ISBN-10: 0-672-2966-2 Text printed in the United States on recycled paper at RR Donnelley in Crawfordsville, Indiana. First printing June 2008 To Heidi, the woman I love. This page intentionally left blank CONTENTS Preface . xv Acknowledgments . xix About the Author . xxi PART I: GETTING STARTED WITH POWERSHELL . 1 Chapter 1: First Steps with Windows PowerShell . 3 What Is Windows PowerShell? . 3 Downloading and Installing PowerShell Community Extensions . 16 Testing the PowerShell Extensions . 18 Downloading and Installing the PowerShellPlus . 19 Testing the PowerShell Editor . 20 Summary . 22 Chapter 2: Commandlets . 25 Introducing Commandlets . 25 Aliases . 29 Expressions . 32 External Commands . 33 Getting Help . 35 Summary . 41 vii viii Contents Chapter 3: Pipelining . 43 Pipelining Basics . 43 Pipeline Processor . 47 Complex Pipelines . 48 Output . 49 Getting User Input . 56 Summary . 58 Chapter 4: Advanced Pipelining . 59 Analyzing Pipeline Content . 59 Filtering Objects . 70 Castrating Objects . 73 Sorting Objects . 74 Grouping Objects . 74 Calculations . 76 Intermediate Steps in the Pipeline . 76 Comparing Objects . 78 Ramifications . 78 Summary . 79 Chapter 5: The PowerShell Navigation Model . 81 Navigation through the Registry . 81 Providers and Drives . 83 Navigation Commandlets . 84 Paths . 85 Defining Drives . 87 Summary . 88 Chapter 6: The PowerShell Script Language . 89 Getting Help . 90 Command Separation . 90 Comments . 90 Variables . 91 Available Types . 92 Numbers . 96 Random Numbers . 98 Contents ix Strings . 99 Date and Time . 102 Arrays . 105 Associative Arrays (Hash Tables) . 106 Operators . 108 Control Structures . 110 Summary . 113 Chapter 7: PowerShell Scripts . 115 A First PowerShell Script Example . 115 Start a PowerShell Script . 117 Including Scripts . 118 Scripting Security . 118 Signing of Scripts . 120 Letting a Script Sleep . 122 Errors and Error Treatment . 122 Summary . 128 Chapter 8: Using Class Libraries . 129 Using .NET Classes . 129 Using COM Classes . 133 Using WMI Classes . 135 Date and Time . 145 Summary . 150 Chapter 9: PowerShell Tools . 151 PowerShell Console . 151 PowerTab . 156 PowerShell IDE . 156 Windows PowerShellPlus . 158 PowerShell Analyzer . 164 PrimalScript . 165 PowerShell Help . 169 Summary . ..

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    501 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us