1. Trang chủ
  2. » Công Nghệ Thông Tin

powershell in depth

633 3.9K 0

Đ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

Cấu trúc

  • Front cover

  • brief contents

  • contents

  • preface

  • acknowledgments

  • about this book

    • Code conventions and downloads

    • Author Online

  • about the authors

  • about the cover illustration

  • Part 1—PowerShell fundamentals

    • 1 Introduction

      • 1.1 Who this book is for

      • 1.2 What this book will teach you

      • 1.3 What this book won’t teach you

      • 1.4 Where we drew the line

      • 1.5 Beyond PowerShell

      • 1.6 Ready?

    • 2 PowerShell hosts

      • 2.1 32-bit vs. 64-bit, and administrator vs. not

      • 2.2 The console

      • 2.3 The PowerShell ISE

      • 2.4 Command history buffer vs. PowerShell’s history

      • 2.5 Transcripts

      • 2.6 Summary

    • 3 Using the PowerShell help system

      • 3.1 The help commands

      • 3.2 Where’s the help?

      • 3.3 Using the help

      • 3.4 “About” help files

      • 3.5 Provider help

      • 3.6 Interpreting command help

      • 3.7 Common parameters

      • 3.8 Summary

    • 4 The basics of PowerShell syntax

      • 4.1 Commands

        • 4.1.1 Aliases: nicknames for commands

        • 4.1.2 Command name tab completion

      • 4.2 Parameters

        • 4.2.1 Truncating parameter names

        • 4.2.2 Parameter name tab completion

      • 4.3 Typing trick: line continuation

      • 4.4 Parenthetical commands and expressions

      • 4.5 Script blocks

      • 4.6 Summary

    • 5 Working with PSSnapins and modules

      • 5.1 There’s only one shell

      • 5.2 PSSnapins vs. modules

      • 5.3 Loading, autoloading, and profiles

      • 5.4 Using extensions

        • 5.4.1 Discovering extensions

        • 5.4.2 Loading extensions

        • 5.4.3 Discovering extensions’ additions

        • 5.4.4 Managing extensions

      • 5.5 Command name conflicts

      • 5.6 Managing module autoloading

      • 5.7 Summary

    • 6 Operators

      • 6.1 Logical and comparison operators

        • 6.1.1 The –contains operator

        • 6.1.2 The -in and -notin operators

        • 6.1.3 Boolean, or logical, operators

        • 6.1.4 Bitwise operators

      • 6.2 Arithmetic operators

      • 6.3 Other operators

        • 6.3.1 String and array manipulation operators

        • 6.3.2 Object type operators

        • 6.3.3 Format operator

        • 6.3.4 Miscellaneous operators

      • 6.4 Summary

    • 7 Working with objects

      • 7.1 Introduction to objects

      • 7.2 Members: properties, methods, and events

      • 7.3 Sorting objects

      • 7.4 Selecting objects

        • 7.4.1 Use 1: choosing properties

        • 7.4.2 Use 2: choosing a subset of objects

        • 7.4.3 Use 3: making custom properties

        • 7.4.4 Use 4: extracting and expanding properties

        • 7.4.5 Use 5: choosing properties and a subset of objects

      • 7.5 Filtering objects

        • 7.5.1 Simplified syntax

        • 7.5.2 Full syntax

      • 7.6 Grouping objects

      • 7.7 Measuring objects

      • 7.8 Enumerating objects

        • 7.8.1 Full syntax

        • 7.8.2 Simplified syntax

      • 7.9 Importing, exporting, and converting objects

      • 7.10 Comparing objects

      • 7.11 Summary

    • 8 The PowerShell pipeline

      • 8.1 How the pipeline works

        • 8.1.1 The old way of piping

        • 8.1.2 The PowerShell way of piping

      • 8.2 Parameter binding ByValue

      • 8.3 Pipeline binding ByPropertyName

      • 8.4 Troubleshooting parameter binding

      • 8.5 When parameter binding lets you down

      • 8.6 The pipeline with external commands

      • 8.7 Summary

    • 9 Formatting

      • 9.1 The time to format

      • 9.2 The formatting system

        • 9.2.1 Is there a predefined view?

        • 9.2.2 What properties should be displayed?

        • 9.2.3 List or table?

      • 9.3 The Format cmdlets

        • 9.3.1 Formatting wide lists

        • 9.3.2 Formatting tables

        • 9.3.3 Formatting lists

        • 9.3.4 Same objects, different formats

      • 9.4 Eliminating confusion and “gotchas”

        • 9.4.1 Formatting is the end of the line

        • 9.4.2 Select or format?

        • 9.4.3 Format, out, export—which?

      • 9.5 Summary

  • Part 2—PowerShell management

    • 10 PowerShell Remoting

      • 10.1 The many forms of remote control

      • 10.2 Remoting overview

        • 10.2.1 Authentication

        • 10.2.2 Firewalls and security

      • 10.3 Using Remoting

        • 10.3.1 Enabling Remoting

        • 10.3.2 1-to-1 Remoting

        • 10.3.3 1-to-many Remoting

        • 10.3.4 Remoting caveats

        • 10.3.5 Remoting options

      • 10.4 PSSessions

        • 10.4.1 Creating a persistent session

        • 10.4.2 Using a session

        • 10.4.3 Managing sessions

        • 10.4.4 Disconnecting and reconnecting sessions

      • 10.5 Advanced session techniques

        • 10.5.1 Session parameters

        • 10.5.2 Session options

      • 10.6 Creating a custom endpoint

        • 10.6.1 Custom endpoints for delegated administration

      • 10.7 Connecting to nondefault endpoints

      • 10.8 Enabling the “second hop”

      • 10.9 Setting up WinRM listeners

      • 10.10 Other configuration scenarios

        • 10.10.1 Cross-domain Remoting

        • 10.10.2 Quotas

        • 10.10.3 Configuring on a remote machine

        • 10.10.4 Key WinRM configuration settings

        • 10.10.5 Adding a machine to your Trusted Hosts list

        • 10.10.6 Using Group Policy to configure Remoting

      • 10.11 Implicit Remoting

      • 10.12 Summary

    • 11 Background jobs and scheduling

      • 11.1 Remoting-based jobs

        • 11.1.1 Starting jobs

        • 11.1.2 Checking job status

        • 11.1.3 Working with child jobs

        • 11.1.4 Waiting for a job

        • 11.1.5 Stopping jobs

        • 11.1.6 Getting job results

        • 11.1.7 Removing jobs

        • 11.1.8 Investigating failed jobs

      • 11.2 WMI jobs

      • 11.3 Scheduled jobs

        • 11.3.1 Scheduled jobs overview

        • 11.3.2 Creating a scheduled job

        • 11.3.3 Managing scheduled jobs

        • 11.3.4 Working with scheduled job results

      • 11.4 Job processes

        • 11.4.1 Jobs created with Start-Job

        • 11.4.2 Jobs created with Invoke-Command

        • 11.4.3 Jobs created through the WMI cmdlets

        • 11.4.4 Jobs created through the scheduler

      • 11.5 Summary

    • 12 Working with credentials

      • 12.1 About credentials

      • 12.2 Using credentials

      • 12.3 Crazy credentials ideas

        • 12.3.1 Packaging your script

        • 12.3.2 Saving a credential object

        • 12.3.3 Creating a credential without the GUI

        • 12.3.4 Supporting credentials in your script

      • 12.4 Summary

    • 13 Regular expressions

      • 13.1 Basic regular expression syntax

      • 13.2 The –match operator

      • 13.3 The select-string cmdlet

      • 13.4 Switch statement

      • 13.5 The REGEX object

      • 13.6 Summary

    • 14 Working with HTML and XML data

      • 14.1 Working with HTML

        • 14.1.1 Retrieving an HTML page

        • 14.1.2 Working with the HTML results

        • 14.1.3 Practical example

        • 14.1.4 Creating HTML output

      • 14.2 Working with XML

        • 14.2.1 Using XML to persist data

        • 14.2.2 Reading arbitrary XML data

        • 14.2.3 Creating XML data and files

        • 14.2.4 Using XML XPath queries

      • 14.3 Summary

    • 15 PSDrives and PSProviders

      • 15.1 Why use PSProviders?

      • 15.2 What are PSProviders?

      • 15.3 What are PSDrives?

      • 15.4 Working with PSDrives

        • 15.4.1 Working with PSDrive items

        • 15.4.2 Working with item properties

      • 15.5 Transactional operations

      • 15.6 Every drive is different

      • 15.7 Summary

    • 16 Variables, arrays, hash tables, and scriptblocks

      • 16.1 Variables

        • 16.1.1 Variable names

        • 16.1.2 Variable types

        • 16.1.3 Being strict with variables

      • 16.2 Built-in variables and the Variable: drive

      • 16.3 Variable commands

      • 16.4 Arrays

      • 16.5 Hash tables and ordered hash tables

        • 16.5.1 Ordered hash tables

        • 16.5.2 Common uses for hash tables

        • 16.5.3 Defining default parameter values

      • 16.6 Scriptblocks

      • 16.7 Summary

    • 17 PowerShell security

      • 17.1 PowerShell security goals

      • 17.2 PowerShell security mechanisms

        • 17.2.1 Script execution requires a path

        • 17.2.2 Filename extension associations

      • 17.3 Execution policy

        • 17.3.1 A digital signature crash course

        • 17.3.2 Understanding script signing

        • 17.3.3 The execution policy in depth

      • 17.4 The PowerShell security debate

      • 17.5 Summary

    • 18 Advanced PowerShell syntax

      • 18.1 Splatting

      • 18.2 Defining default parameter values

      • 18.3 Running external utilities

      • 18.4 Expressions in quotes: $($cool)

      • 18.5 Parentheticals as objects

      • 18.6 Increase the format enumeration limit

      • 18.7 Hash tables as objects

      • 18.8 Summary

  • Part 3—PowerShell scripting and automation

    • 19 PowerShell’s scripting language

      • 19.1 Defining conditions

      • 19.2 Loops: For, Do, While, Until

        • 19.2.1 The For loop

        • 19.2.2 The other loops

      • 19.3 ForEach

      • 19.4 Break and Continue

      • 19.5 If . . . ElseIf . . . Else

      • 19.6 Switch

      • 19.7 Mastering the punctuation

      • 19.8 Summary

    • 20 Basic scripts and functions

      • 20.1 Script or function?

      • 20.2 Execution lifecycle and scope

      • 20.3 Starting point: a command

      • 20.4 Accepting input

      • 20.5 Creating output

      • 20.6 “Filtering” scripts

      • 20.7 Moving to a function

      • 20.8 Summary

    • 21 Creating objects for output

      • 21.1 Why output objects?

      • 21.2 Syntax for creating custom objects

        • 21.2.1 Technique 1: using a hash table

        • 21.2.2 Technique 2: using Select-Object

        • 21.2.3 Technique 3: using Add-Member

        • 21.2.4 Technique 4: using a Type declaration

        • 21.2.5 Technique 5: creating a new class

        • 21.2.6 What’s the difference?

      • 21.3 Complex objects: collections as properties

      • 21.4 Applying a type name to custom objects

      • 21.5 So, why bother?

      • 21.6 Summary

    • 22 Scope

      • 22.1 Understanding scope

      • 22.2 Observing scope in action

      • 22.3 Dot sourcing

      • 22.4 Manipulating cross-scope elements

      • 22.5 Being private

      • 22.6 Being strict

      • 22.7 Summary

    • 23 PowerShell workflows

      • 23.1 Workflow overview

      • 23.2 Workflow basics

        • 23.2.1 Common parameters for workflows

        • 23.2.2 Activities and stateless execution

        • 23.2.3 Persisting state

        • 23.2.4 Suspending and resuming workflows

        • 23.2.5 Workflow limitations

        • 23.2.6 Parallelism

      • 23.3 General workflow design strategy

      • 23.4 Example workflow scenario

      • 23.5 Writing the workflow

      • 23.6 Workflows vs. functions

      • 23.7 Specific workflow techniques

        • 23.7.1 Sequences

        • 23.7.2 InlineScript

      • 23.8 Running a workflow

        • 23.8.1 Workflow jobs

        • 23.8.2 Suspending and restarting a workflow

        • 23.8.3 Workflow credentials

      • 23.9 A practical example

      • 23.10 Invoke-AsWorkflow

      • 23.11 PSWorkflowSession

      • 23.12 Troubleshooting a workflow

      • 23.13 Summary

    • 24 Advanced syntax for scripts and functions

      • 24.1 Starting point

      • 24.2 Advanced parameters

      • 24.3 Variations on parameter inputs

      • 24.4 Parameter aliases

      • 24.5 Parameter validation

      • 24.6 Parameter sets

      • 24.7 WhatIf and Confirm parameters

      • 24.8 Verbose output

      • 24.9 Summary

    • 25 Script modules and manifest modules

      • 25.1 Making a script module

      • 25.2 Exporting module members

      • 25.3 Making a module manifest

      • 25.4 Creating dynamic modules

      • 25.5 Summary

    • 26 Custom formatting views

      • 26.1 Object type names

      • 26.2 Getting view templates

      • 26.3 Starting a view file

      • 26.4 Adding view types

      • 26.5 Importing view data

      • 26.6 Using named views

      • 26.7 Going further

      • 26.8 Summary

    • 27 Custom type extensions

      • 27.1 What are type extensions?

      • 27.2 Creating and loading a type extension file

      • 27.3 Making type extensions

        • 27.3.1 AliasProperty

        • 27.3.2 ScriptProperty

        • 27.3.3 ScriptMethod

        • 27.3.4 DefaultDisplayPropertySet

      • 27.4 A complete example

      • 27.5 Updating type data dynamically

      • 27.6 Get-TypeData

      • 27.7 Remove-TypeData

      • 27.8 Summary

    • 28 Data language and internationalization

      • 28.1 Internationalization basics

      • 28.2 Adding a data section

      • 28.3 Storing translated strings

      • 28.4 Testing localization

      • 28.5 Summary

    • 29 Writing help

      • 29.1 Comment-based help

      • 29.2 Writing About topics

      • 29.3 XML-based help

      • 29.4 Summary

    • 30 Error handling techniques

      • 30.1 About errors and exceptions

      • 30.2 Using $ErrorActionPreference and –ErrorAction

      • 30.3 Using –ErrorVariable

      • 30.4 Using $Error

      • 30.5 Trap constructs

      • 30.6 Try...Catch...Finally constructs

      • 30.7 Summary

    • 31 Debugging tools and techniques

      • 31.1 Debugging: all about expectations

      • 31.2 Write-Debug

      • 31.3 Breakpoints

      • 31.4 Using Set-PSDebug

      • 31.5 Debugging in third-party editors

      • 31.6 Summary

    • 32 Functions that work like cmdlets

      • 32.1 Defining the task

      • 32.2 Building the command

      • 32.3 Parameterizing the pipeline

      • 32.4 Adding professional features

      • 32.5 Error handling

        • 32.5.1 Adding verbose and debug output

        • 32.5.2 Defining a custom object name

      • 32.6 Making it a function and adding help

      • 32.7 Creating a custom view

      • 32.8 Creating a type extension

      • 32.9 Making a module manifest

      • 32.10 Summary

    • 33 Tips and tricks for creating reports

      • 33.1 What not to do

      • 33.2 Working with HTML fragments and files

        • 33.2.1 Getting the information

        • 33.2.2 Producing an HTML fragment

        • 33.2.3 Assembling the final HTML page

      • 33.3 Sending email

      • 33.4 Summary

  • Part 4—Advanced PowerShell

    • 34 Working with the Component Object Model (COM)

      • 34.1 Introduction to COM objects

      • 34.2 Instantiating COM objects in PowerShell

      • 34.3 Accessing and using COM objects’ members

      • 34.4 PowerShell and COM examples

      • 34.5 Summary

    • 35 Working with .NET Framework objects

      • 35.1 Classes, instances, and members

      • 35.2 .NET Framework syntax in PowerShell

      • 35.3 .NET support in PowerShell

      • 35.4 Accessing static members

      • 35.5 Finding the right framework bits

      • 35.6 Creating and working with instances

      • 35.7 Summary

    • 36 Accessing databases

      • 36.1 Native SQL vs. OLEDB

      • 36.2 Connecting to data sources

      • 36.3 Querying data

        • 36.3.1 Databases with DataAdapters

        • 36.3.2 Databases with DataReaders

      • 36.4 Adding, changing, and deleting data

      • 36.5 Calling stored procedures

      • 36.6 A module to make it easier

      • 36.7 Summary

    • 37 Proxy functions

      • 37.1 The purpose of proxy functions

      • 37.2 How proxy functions work

      • 37.3 Creating a basic proxy function

      • 37.4 Adding a parameter

      • 37.5 Removing a parameter

      • 37.6 Turning it into a function

      • 37.7 Summary

    • 38 Building a GUI

      • 38.1 WinForms via PowerShell Studio

        • 38.1.1 Creating the GUI

        • 38.1.2 Adding the code

        • 38.1.3 Using the script

      • 38.2 Windows Presentation Foundation (WPF) and ShowUI

      • 38.3 WinForms vs. WPF

      • 38.4 Ideas for leveraging a GUI tool

      • 38.5 Summary

    • 39 WMI and CIM

      • 39.1 What is WMI?

      • 39.2 WMI cmdlets

        • 39.2.1 Get-WmiObject

        • 39.2.2 Remove-WmiObject

        • 39.2.3 Set-WmiInstance

        • 39.2.4 Invoke-WmiMethod

        • 39.2.5 Register-WmiEvent

      • 39.3 CIM cmdlets

        • 39.3.1 Get-CIMClass

        • 39.3.2 Get-CimInstance

        • 39.3.3 Remove-CimInstance

        • 39.3.4 Set-CimInstance

        • 39.3.5 Invoke-CimMethod

        • 39.3.6 Register-CimIndicationEvent

      • 39.4 CIM sessions

      • 39.5 “Cmdlets over objects”

      • 39.6 Summary

    • 40 Best practices

      • 40.1 PowerShell general best practices

      • 40.2 PowerShell scripting best practices

      • 40.3 PowerShell in the enterprise best practices

  • index

    • Symbols

    • Numerics

    • A

    • B

    • C

    • D

    • E

    • F

    • G

    • H

    • I

    • J

    • K

    • L

    • M

    • N

    • O

    • P

    • Q

    • R

    • S

    • T

    • U

    • V

    • W

    • X

  • Back cover

Nội dung

MANNING Don Jones Richard Siddaway Jeffery Hicks An administrator’s guide Covers PowerShell 3.0 www.it-ebooks.info PowerShell in Depth www.it-ebooks.info www.it-ebooks.info PowerShell in Depth A N ADMINISTRATOR ’ S GUIDE DON JONES RICHARD SIDDAWAY JEFFERY HICKS MANNING S HELTER I SLAND 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 Copyeditor: Liz Welch PO Box 261 Technical proofreader: Aleksandar Nikolic Shelter Island, NY 11964 Proofreader: Linda Recktenwald Typesetter: Dennis Dalinnik Cover designer: Marija Tudor ISBN: 9781617290558 Printed in the United States of America 1 2 3 4 5 6 7 8 9 10 – MAL – 19 18 17 16 15 14 13 www.it-ebooks.info v brief contents P ART 1 P OWER S HELL FUNDAMENTALS . 1 1 ■ Introduction 3 2 ■ PowerShell hosts 7 3 ■ Using the PowerShell help system 17 4 ■ The basics of PowerShell syntax 29 5 ■ Working with PSSnapins and modules 39 6 ■ Operators 46 7 ■ Working with objects 60 8 ■ The PowerShell pipeline 93 9 ■ Formatting 111 P ART 2 P OWER S HELL MANAGEMENT 127 10 ■ PowerShell Remoting 129 11 ■ Background jobs and scheduling 160 12 ■ Working with credentials 174 13 ■ Regular expressions 184 14 ■ Working with HTML and XML data 196 www.it-ebooks.info BRIEF CONTENTS vi 15 ■ PSDrives and PSProviders 210 16 ■ Variables, arrays, hash tables, and scriptblocks 224 17 ■ PowerShell security 244 18 ■ Advanced PowerShell syntax 257 P ART 3 P OWER S HELL SCRIPTING AND AUTOMATION 275 19 ■ PowerShell’s scripting language 277 20 ■ Basic scripts and functions 291 21 ■ Creating objects for output 301 22 ■ Scope 317 23 ■ PowerShell workflows 332 24 ■ Advanced syntax for scripts and functions 359 25 ■ Script modules and manifest modules 379 26 ■ Custom formatting views 391 27 ■ Custom type extensions 403 28 ■ Data language and internationalization 417 29 ■ Writing help 429 30 ■ Error handling techniques 435 31 ■ Debugging tools and techniques 447 32 ■ Functions that work like cmdlets 466 33 ■ Tips and tricks for creating reports 485 P ART 4 A DVANCED P OWER S HELL 495 34 ■ Working with the Component Object Model (COM) 497 35 ■ Working with .NET Framework objects 505 36 ■ Accessing databases 517 37 ■ Proxy functions 525 38 ■ Building a GUI 538 39 ■ WMI and CIM 557 40 ■ Best practices 584 www.it-ebooks.info vii contents preface xxi acknowledgments xxiii about this book xxv about the authors xxvii about the cover illustration xxix P ART 1 P OWER S HELL FUNDAMENTALS . 1 1 Introduction 3 1.1 Who this book is for 3 1.2 What this book will teach you 4 1.3 What this book won’t teach you 4 1.4 Where we drew the line 5 1.5 Beyond PowerShell 5 1.6 Ready? 6 2 PowerShell hosts 7 2.1 32-bit vs. 64-bit, and administrator vs. not 8 2.2 The console 10 2.3 The PowerShell ISE 12 www.it-ebooks.info CONTENTS viii 2.4 Command history buffer vs. PowerShell’s history 15 2.5 Transcripts 16 2.6 Summary 16 3 Using the PowerShell help system 17 3.1 The help commands 17 3.2 Where’s the help? 18 3.3 Using the help 20 3.4 “About” help files 23 3.5 Provider help 24 3.6 Interpreting command help 25 3.7 Common parameters 27 3.8 Summary 28 4 The basics of PowerShell syntax 29 4.1 Commands 30 Aliases: nicknames for commands 31 ■ Command name tab completion 32 4.2 Parameters 32 Truncating parameter names 34 ■ Parameter name tab completion 35 4.3 Typing trick: line continuation 35 4.4 Parenthetical commands and expressions 36 4.5 Script blocks 37 4.6 Summary 38 5 Working with PSSnapins and modules 39 5.1 There’s only one shell 39 5.2 PSSnapins vs. modules 40 5.3 Loading, autoloading, and profiles 41 5.4 Using extensions 41 Discovering extensions 41 ■ Loading extensions 43 Discovering extensions’ additions 43 ■ Managing extensions 44 5.5 Command name conflicts 44 5.6 Managing module autoloading 45 5.7 Summary 45 www.it-ebooks.info CONTENTS ix 6 Operators 46 6.1 Logical and comparison operators 47 The –contains operator 48 ■ The -in and -notin operators 49 Boolean, or logical, operators 50 ■ Bitwise operators 51 6.2 Arithmetic operators 53 6.3 Other operators 55 String and array manipulation operators 55 Object type operators 56 ■ Format operator 57 Miscellaneous operators 58 6.4 Summary 59 7 Working with objects 60 7.1 Introduction to objects 61 7.2 Members: properties, methods, and events 63 7.3 Sorting objects 68 7.4 Selecting objects 69 Use 1: choosing properties 70 ■ Use 2: choosing a subset of objects 71 ■ Use 3: making custom properties 73 Use 4: extracting and expanding properties 75 Use 5: choosing properties and a subset of objects 79 7.5 Filtering objects 79 Simplified syntax 79 ■ Full syntax 81 7.6 Grouping objects 81 7.7 Measuring objects 83 7.8 Enumerating objects 84 Full syntax 85 ■ Simplified syntax 85 7.9 Importing, exporting, and converting objects 86 7.10 Comparing objects 90 7.11 Summary 92 8 The PowerShell pipeline 93 8.1 How the pipeline works 93 The old way of piping 94 ■ The PowerShell way of piping 95 8.2 Parameter binding ByValue 96 8.3 Pipeline binding ByPropertyName 98 8.4 Troubleshooting parameter binding 104 www.it-ebooks.info [...]... 35.7 36.1 36.2 36.3 Introduction to COM objects 498 Instantiating COM objects in PowerShell 500 Accessing and using COM objects’ members 500 PowerShell and COM examples 503 Summary 504 Classes, instances, and members 506 NET Framework syntax in PowerShell 507 NET support in PowerShell 508 Accessing static members 509 Finding the right framework bits 509 Creating and working with instances 514 Summary... 465 Summary 465 Defining the task 467 Building the command 468 Parameterizing the pipeline 469 Adding professional features 472 Error handling 472 Adding verbose and debug output 474 object name 477 32.6 32.7 32.8 32.9 32.10 ■ Making it a function and adding help Creating a custom view 479 Creating a type extension 480 Making a module manifest 481 Summary 484 www.it-ebooks.info Defining a custom 477... endpoints Enabling the “second hop” 149 Setting up WinRM listeners 150 Other configuration scenarios 152 148 Cross-domain Remoting 152 Quotas 153 Configuring on a remote machine 154 Key WinRM configuration settings 154 Adding a machine to your Trusted Hosts list 155 Using Group Policy to configure Remoting 156 ■ ■ ■ ■ 10.11 10.12 11 Implicit Remoting 157 Summary 159 Background jobs and scheduling 160... www.manning.com/PowerShellinDepth We, along with our technical reviewer, have strived to test and retest everything But sometimes errors will still sneak through We encourage you to use the Author Online forum for this book at www.manning.com/PowerShellinDepth to post any corrections, as well as your comments or questions on the book’s content Author Online Purchase of PowerShell in Depth includes... in most IT roles He has always been interested in automation tech- niques (including automating job creation and submission on mainframes many years ago) PowerShell caught his interest and Richard has been using it since the early beta versions He regularly blogs about PowerShell, and using PowerShell, at http:/ / msmvps.com/blogs/richardsiddaway/default.aspx Richard founded and still runs the UK PowerShell. .. How proxy functions work 526 Creating a basic proxy function 526 Adding a parameter 528 Removing a parameter 532 Turning it into a function 534 Summary 536 WinForms via PowerShell Studio Creating the GUI 540 Using the script 548 38.2 38.3 38.4 38.5 39 ■ 539 Adding the code 543 Windows Presentation Foundation (WPF) and ShowUI 552 WinForms vs WPF 554 Ideas for leveraging a GUI tool 555 Summary 556 WMI... conventions and downloads All source code in listings or in text is in a fixed-width font like this to separate it from ordinary text Code annotations accompany many of the listings, highlighting important concepts In some cases, numbered bullets link to explanations that follow the listing The code samples are based on PowerShell 3.0 We intended the samples to be instructive, but we did not design them... 1-to-1 Remoting 133 Remoting caveats 136 140 Creating a persistent session 140 Using a session 140 Managing sessions 141 Disconnecting and reconnecting sessions 141 ■ ■ 10.5 Advanced session techniques Session parameters 10.6 144 ■ 144 Session options Creating a custom endpoint 145 145 Custom endpoints for delegated administration www.it-ebooks.info 147 CONTENTS 10.7 10.8 10.9 10.10 xi Connecting to nondefault... and scheduling 160 11.1 Remoting-based jobs 160 Starting jobs 161 Checking job status 162 Working with child jobs 162 Waiting for a job 164 Stopping jobs 164 Getting job results 164 Removing jobs 165 Investigating failed jobs 166 ■ ■ ■ ■ ■ 11.2 11.3 WMI jobs 166 Scheduled jobs 167 Scheduled jobs overview 168 Creating a scheduled job 168 Managing scheduled jobs 169 Working with scheduled job results... a PowerShell MVP for the last five years A regular speaker and writer on PowerShell topics, his previous Manning books include PowerShell in Practice and PowerShell and WMI JEFFERY HICKS is a Microsoft MVP in Windows PowerShell, Microsoft Certified Trainer and an IT veteran with 20 years of experience, much of it spent as an IT consultant xxvii www.it-ebooks.info xxviii ABOUT THE AUTHORS specializing . MANNING Don Jones Richard Siddaway Jeffery Hicks An administrator’s guide Covers PowerShell 3.0 www.it-ebooks.info PowerShell in Depth www.it-ebooks.info www.it-ebooks.info PowerShell in Depth A N . way of piping 95 8.2 Parameter binding ByValue 96 8.3 Pipeline binding ByPropertyName 98 8.4 Troubleshooting parameter binding 104 www.it-ebooks.info CONTENTS x 8.5 When parameter binding lets. 85 7.9 Importing, exporting, and converting objects 86 7.10 Comparing objects 90 7.11 Summary 92 8 The PowerShell pipeline 93 8.1 How the pipeline works 93 The old way of piping 94 ■ The PowerShell

Ngày đăng: 05/05/2014, 15:57

TỪ KHÓA LIÊN QUAN