learn windows powershell 3 in a month of lunches 2nd edition

367 1.3K 0
learn  windows  powershell  3  in  a  month  of  lunches  2nd  edition

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

www.it-ebooks.info Praise for the First Edition The closest thing I’ve seen to a class in a book. Contains tons of useful exercises that instill PowerShell prowess by hands-on learning. —Chuck Durfee Sr. Software Engineer, Graebel Companies From beginners to intermediate—this is THE only book you need. Don Jones is a PowerShell superstar and in this book you will see why. —David Moravec SCCM Administrator, PowerShell.cz The seminal guide to learning Powershell—highly recommended. —Ray Booysen Developer, BNP Paribas The book I wish I’d had when I started PowerShell! —Richard Siddaway IT Architect and PowerShell MVP This book not only teaches you PowerShell, it also teaches you to become an expert in PowerShell. —Nikander Bruggeman and Margriet Bruggeman, .NET consultants, Lois & Clark IT Services www.it-ebooks.info www.it-ebooks.info Learn Windows PowerShell 3 in a Month of Lunches SECOND EDITION DON JONES JEFFERY HICKS MANNING SHELTER ISLAND www.it-ebooks.info For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact Special Sales Department Manning Publications Co. 20 Baldwin Road PO Box 261 Shelter Island, NY 11964 Email: orders@manning.com ©2013 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine. Manning Publications Co. Development editor: Cynthia Kane 20 Baldwin Road Technical Proofreaders: James Berkenbile, Trent Whiteley PO Box 261 Copyeditor: Andy Carroll Shelter Island, NY 11964 Proofreader: Maureen Spencer Typesetter: Dottie Marsico Cover designer: Marija Tudor ISBN 9781617291081 Printed in the United States of America 12345678910–MAL–171615141312 www.it-ebooks.info v brief contents 1 ■ Before you begin 1 2 ■ Meet PowerShell 9 3 ■ Using the help system 20 4 ■ Running commands 36 5 ■ Working with providers 49 6 ■ The pipeline: connecting commands 61 7 ■ Adding commands 74 8 ■ Objects: data by another name 85 9 ■ The pipeline, deeper 97 10 ■ Formatting—and why it’s done on the right 119 11 ■ Filtering and comparisons 134 12 ■ A practical interlude 143 13 ■ Remote control: one to one, and one to many 151 14 ■ Using Windows Management Instrumentation 169 15 ■ Multitasking with background jobs 182 16 ■ Working with many objects, one at a time 196 17 ■ Security alert! 211 18 ■ Variables: a place to store your stuff 222 www.it-ebooks.info BRIEF CONTENTSvi 19 ■ Input and output 238 20 ■ Sessions: remote control with less work 247 21 ■ You call this scripting? 257 22 ■ Improving your parameterized script 269 23 ■ Advanced remoting configuration 278 24 ■ Using regular expressions to parse text files 287 25 ■ Additional random tips, tricks, and techniques 294 26 ■ Using someone else’s script 308 27 ■ Never the end 316 28 ■ PowerShell cheat sheet 319 www.it-ebooks.info vii contents preface xvii about this book xix author online xx about the authors xxii acknowledgments xxv 1 Before you begin 1 1.1 Why you can’t afford to ignore PowerShell 1 1.2 Is this book for you? 3 1.3 How to use this book 4 1.4 Setting up your lab environment 5 1.5 Installing Windows PowerShell 6 1.6 Online resources 7 1.7 Being immediately effective with PowerShell 8 2 Meet PowerShell 9 2.1 Choose your weapon 9 The console window 11 ■ The Integrated Scripting Environment (ISE) 13 2.2 It’s typing class all over again 15 2.3 Common points of confusion 16 www.it-ebooks.info CONTENTSviii 2.4 What version is this? 17 2.5 Lab 18 2.6 Further exploration 19 3 Using the help system 20 3.1 The help system: how you discover commands 20 3.2 Updatable help 22 3.3 Asking for help 23 3.4 Using help to find commands 24 3.5 Interpreting the help 26 Parameter sets and common parameters 26 ■ Optional and mandatory parameters 27 ■ Positional parameters 28 Parameter values 30 ■ Finding command examples 32 3.6 Accessing “about” topics 32 3.7 Accessing online help 34 3.8 Lab 34 4 Running commands 36 4.1 Not scripting, but running commands 36 4.2 The anatomy of a command 37 4.3 The cmdlet naming convention 38 4.4 Aliases: nicknames for commands 39 4.5 Taking shortcuts 40 Truncating parameter names 40 ■ Parameter name aliases 41 Positional parameters 41 4.6 Cheating, a bit: Show-Command 42 4.7 Support for external commands 44 4.8 Dealing with errors 46 4.9 Common points of confusion 47 Typing cmdlet names 47 ■ Typing parameters 47 4.10 Lab 48 5 Working with providers 49 5.1 What are providers? 49 5.2 How the filesystem is organized 51 5.3 How the filesystem is like other data stores 53 www.it-ebooks.info CONTENTS ix 5.4 Navigating the filesystem 54 5.5 Using wildcards and literal paths 55 5.6 Working with other providers 57 5.7 Lab 60 5.8 Further exploration 60 6 The pipeline: connecting commands 61 6.1 Connect one command to another: less work for you 61 6.2 Exporting to a CSV or an XML file 62 Exporting to CSV 63 ■ Exporting to XML 64 Comparing files 65 6.3 Piping to a file or a printer 67 6.4 Converting to HTML 68 6.5 Using cmdlets that modify the system: killing processes and stopping services 69 6.6 Common points of confusion 70 6.7 Lab 72 7 Adding commands 74 7.1 How one shell can do everything 74 7.2 About product-specific “management shells” 75 7.3 Extensions: finding and adding snap-ins 76 7.4 Extensions: finding and adding modules 78 7.5 Command conflicts and removing extensions 80 7.6 Playing with a new module 81 7.7 Profile scripts: preloading extensions when the shell starts 82 7.8 Common points of confusion 84 7.9 Lab 84 8 Objects: data by another name 85 8.1 What are objects? 85 8.2 Why PowerShell uses objects 86 8.3 Discovering objects: Get-Member 88 8.4 Object attributes, or “properties” 89 8.5 Object actions, or “methods” 90 www.it-ebooks.info [...]... 23. 3 23. 4 257 Starting point 269 Getting PowerShell to do the hard work 270 Making parameters mandatory 271 Adding parameter aliases 2 73 Validating parameter input 274 Adding the warm and fuzzies with verbose output Lab 277 Advanced remoting configuration 23. 1 23. 2 252 280 ■ Registering the Enabling multihop remoting 2 83 Digging deeper into remoting authentication 284 Defaults for mutual authentication... CloudShare.com as an inexpensive way to spin up several virtual machines in the cloud—if such a scenario interests you, look into that service, or something like it Note that CloudShare.com isn’t currently available in all countries 1.5 Installing Windows PowerShell Windows PowerShell v3 has been available for most versions of Windows since the release of Windows Server 2008, Windows Server 2008 R2, Windows. .. most of the examples in this book—and to complete all of the labs—is a copy of Windows that has PowerShell v3 installed The copy can be Windows Vista, Windows 7, Windows Server 2008, Windows Server 2008 R2, Windows 8, or Windows Server 2012 Note that PowerShell might not exist on certain editions of Windows, such as “Starter” editions If you’re going to play with PowerShell, you’ll have to invest in a. .. early releases of a new Microsoft product code-named “Monad”—which later became Windows PowerShell Don lives in Las Vegas and travels all over the world delivering IT training (especially in PowerShell) and speaking at IT conferences JEFFERY HICKS is a multi-year Microsoft MVP in Windows PowerShell, a Microsoft Certified Trainer, and an IT veteran with 20 years of experience, much of it spent as an... typing! Longer code snippets are given in listings and are available for download at http:// Morelunches.com (just click on this book’s cover image and look for the “Downloads” section), as well as from the publisher’s website at www.manning.com/ LearnWindowsPowerShell3inaMonthofLunchesSecondEdition That said, there are a few conventions that you should be aware of Code will always appear in a special... www.manning.com/LearnWindowsPowerShell3inaMonthofLunchesSecondEdition or to www.manning.com/jones3 and click the Author Online link This page provides information on how to get on the forum once you are registered, what kind of help is available, and the rules of conduct in the forum Manning’s commitment to our readers is to provide a venue where a meaningful dialogue between individual readers and... will pay off Let’s start by considering what life was like before PowerShell came along, and look at some of the advantages of using this shell LIFE WITHOUT POWERSHELL Windows administrators have always been happy to click around in the graphical user interface (GUI) to accomplish their chores After all, the GUI is largely the whole point of Windows the operating system isn’t called “Text,” after all... version of Windows that has it Also note that some of the labs rely on functionality that’s new in Windows 8 and Windows Server 2012 At the start of each lab, we’ll tell you what operating system you need in order to complete the lab We do recommend having a Windows 8 or Windows Server 2012 computer to play with—even if it’s in a virtual machine Keep in mind that, throughout this book, we’re assuming you’ll... exploration 2 93 26 ■ -replace 30 0 Never the end 28 PowerShell cheat sheet 28.1 28.2 299 296 ■ -join and -split 299 30 8 The script 30 9 It’s a line-by-line examination Lab 31 3 27 27.1 27.2 27 .3 Customizing the prompt String manipulation 30 1 Date manipulation 30 2 Dealing with WMI dates 30 4 Setting default parameter values 30 5 Playing with script blocks 30 6 More tips, tricks, and techniques 30 7 Using someone... Framework v4 at a minimum, and it prefers to have the latest and greatest version of the framework that you can get We recommend also installing at least NET Framework v3.5 SP 1 and NET Framework v4.0 to get the maximum functionality from the shell TIP Installing PowerShell v3 also installs some companion technologies, including the Windows Remote Management (WinRM) service, which you’ll learn more about . sets and common parameters 26 ■ Optional and mandatory parameters 27 ■ Positional parameters 28 Parameter values 30 ■ Finding command examples 32 3. 6 Accessing “about” topics 32 3. 7 Accessing. Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy. online help 34 3. 8 Lab 34 4 Running commands 36 4.1 Not scripting, but running commands 36 4.2 The anatomy of a command 37 4 .3 The cmdlet naming convention 38 4.4 Aliases: nicknames for commands

Ngày đăng: 05/05/2014, 14:44

Từ khóa liên quan

Mục lục

  • PowerShell 3

  • brief contents

  • contents

  • preface

  • about this book

    • Author Online

    • about the authors

    • acknowledgments

    • 1 Before you begin

      • 1.1 Why you can’t afford to ignore PowerShell

      • 1.2 Is this book for you?

      • 1.3 How to use this book

      • 1.4 Setting up your lab environment

      • 1.5 Installing Windows PowerShell

      • 1.6 Online resources

      • 1.7 Being immediately effective with PowerShell

      • 2 Meet PowerShell

        • 2.1 Choose your weapon

          • 2.1.1 The console window

          • 2.1.2 The Integrated Scripting Environment (ISE)

          • 2.2 It’s typing class all over again

          • 2.3 Common points of confusion

          • 2.4 What version is this?

          • 2.5 Lab

Tài liệu cùng người dùng

Tài liệu liên quan