Windows PowerShell in Action, Third Edition
Bruce Payette and Richard Siddaway
  • MEAP began October 2015
  • Publication in Spring 2017 (estimated)
  • ISBN 9781633430297
  • 625 pages (estimated)
  • printed in black & white
Windows PowerShell in Action, Third Edition is a completely revised edition of the bestselling book on PowerShell. It keeps the same crystal-clear introduction to PowerShell as the last edition and adds extensive coverage of v3, v4, and v5 features such as PowerShell Workflows, Desired State Configuration, PowerShell classes and the PowerShell APIs, new error handling and debugging features. It includes full chapters on these topics and also covers new language elements and operators, PowerShell remoting, CIM, events, working with data such as XML and flat files, The Second Edition's coverage of batch scripting and string processing, COM, WMI, and .NET have all been significantly revised and expanded. The book includes many popular usage scenarios and is rich in interesting examples that will spark your imagination. This is the definitive book on PowerShell - whichever version you use.
Table of Contents detailed table of contents

1. Welcome to PowerShell

1.1. What is PowerShell?

1.1.1. Shells, command lines, and scripting languages

1.2. PowerShell example code

1.2.1. Navigation and basic operations

1.2.2. Basic expressions and variables

1.2.3. Processing data

1.2.4. Flow-control statements

1.2.5. Scripts and functions

1.2.6. Remote administration

1.3. Core concepts

1.3.1. Command concepts and terminology

1.3.2. Commands and cmdlets

1.3.3. Command categories

1.3.4. Aliases and elastic syntax

1.4. Parsing the PowerShell language

1.4.1. How PowerShell parses

1.4.2. Quoting

1.4.3. Expression-mode and command-mode parsing

1.4.4. Statement termination

1.4.5. Comment syntax in PowerShell

1.5. How the pipeline works

1.5.1. Pipelines and streaming behavior

1.5.2. Parameters and parameter binding

1.6. Formatting and output

1.6.1. The formatting cmdlets

1.6.2. The outputter cmdlets

1.7. Summary

2. Working with types

2.1. Type management in the wild, wild West

2.1.1. What the Heck are Types and Classes?

2.1.2. PowerShell: a type-promiscuous language

2.1.3. The type system and type adaptation

2.1.4. Finding the Available Types

2.2. Basic types and literals

2.2.1. String literals

2.2.2. Numbers and numeric literals

2.3. Collections: dictionaries and hashtables

2.3.1. Creating and inspecting hashtables

2.3.2. Ordered hash tables

2.3.3. Modifying and manipulating hashtables

2.3.4. Hashtables as reference types

2.4. Collections: arrays and sequences

2.4.1. Collecting pipeline output as an array

2.4.2. Array indexing

2.4.3. Polymorphism in arrays

2.4.4. Arrays as reference types

2.4.5. Singleton Arrays and Empty Arrays

2.5. Type literals

2.5.1. Type name aliases

2.5.2. Generic type literals

2.5.3. Accessing static members with type literals

2.6. Type conversions

2.6.1. How type conversion works

2.6.2. PowerShell's type-conversion algorithm

2.6.3. Special type conversions in parameter binding

2.7. Summary

3. Operators and expressions

3.1. Arithmetic operators

3.1.1. The addition operator

3.1.2. The multiplication operator

3.1.3. Subtraction, division, and the modulus operator

3.2. The assignment operators

3.2.1. Multiple assignments

3.2.2. Multiple assignments with type qualifiers

3.2.3. Assignment operations as value expressions

3.3. Comparison operators

3.3.1. Scalar comparisons

3.3.2. Comparisons and case sensitivity

3.3.3. Using comparison operators with collections

3.4. Pattern matching and text manipulation

3.4.1. Wildcard patterns and the -like operator

3.4.2. Regular expressions

3.4.3. The -match operator

3.4.4. The -replace operator

3.4.5. The -join operator

3.4.6. The -split operator

3.5. Logical and bitwise operators

3.6. Where and ForEach methods

3.6.1. Where method

3.6.2. ForEach method

3.7. Summary

4. Advanced operators and variables

4.1. Operators for working with types

4.2. The unary operators

4.3. Grouping and subexpressions

4.3.1. Subexpressions $( …​ )

4.3.2. Array subexpressions @( …​ )

4.4. Array operators

4.4.1. The comma operator

4.4.2. The range operator

4.4.3. Array indexing and slicing

4.4.4. Using the range operator with arrays

4.4.5. Working with multidimensional arrays

4.5. Property and method operators

4.5.1. The dot operator

4.5.2. Static methods and the double-colon operator

4.5.3. Indirect method invocation

4.6. The format operator

4.7. Redirection and the redirection operators

4.8. Working with variables

4.8.1. Creating variables

4.8.2. Variable name syntax

4.8.3. Working with the variable cmdlets

4.8.4. Splatting a variable

4.9. Summary

5. Flow control in scripts

5.1. The conditional statement

5.2. Looping statements

5.2.1. The while loop

5.2.2. The do-while loop

5.2.3. The for loop

5.2.4. The foreach loop

5.3. Labels, break, and continue

5.4. The switch statement

5.4.1. Basic use of the switch statement

5.4.2. Using wildcard patterns with the switch statement

5.4.3. Using regular expressions with the switch statement

5.4.4. Processing files with the switch statement

5.4.5. Using the $switch loop enumerator in the switch statement

5.5. Flow control using cmdlets

5.5.1. The ForEach-Object cmdlet

5.5.2. The Where-Object cmdlet

5.6. Statements as values

5.7. A word about performance

5.8. Summary

6. PowerShell functions

6.1. Fundamentals of PowerShell functions

6.1.1. Passing arguments using $args

6.1.2. Example functions: ql and qs

6.2. Declaring formal parameters for a function

6.2.1. Mixing named and positional parameters

6.2.2. Adding type constraints to parameters

6.2.3. Handling variable numbers of arguments

6.2.4. Initializing function parameters with default values

6.2.5. Using switch parameters to define command switches

6.2.6. Switch parameters vs. Boolean parameters

6.3. Returning values from functions

6.3.1. Debugging problems in function output

6.3.2. The return statement

6.4. Using simple functions in a pipeline

6.4.1. Functions with begin, process, and end blocks

6.5. Managing function definitions in a session

6.6. Variable scoping in functions

6.6.1. Declaring variables

6.6.2. Using variable scope modifiers

6.7. Summary

7. Advanced functions and scripts

7.1. PowerShell scripts

7.1.1. Script execution policy

7.1.2. Passing arguments to scripts

7.1.3. Exiting scripts and the exit statement

7.1.4. Scopes and scripts

7.1.5. Managing your scripts

7.1.6. Running PowerShell scripts from other applications

7.2. Writing advanced functions and scripts

7.2.1. Specifying script and function attributes

7.2.2. The CmdletBinding attribute

7.2.3. The OutputType attribute

7.2.4. Specifying parameter attributes

7.2.5. Creating parameter aliases with the Alias attribute

7.2.6. Parameter validation attributes

7.3. Dynamic parameters and dynamicParam

7.3.1. Steps for adding a dynamic parameter

7.3.2. When should dynamic parameters be used?

7.4. Cmdlet default parameter values

7.4.1. Creating default values

7.4.2. Modifying default values

7.4.3. Using scriptblocks to determine default value

7.5. Documenting functions and scripts

7.5.1. Automatically generated help fields

7.5.2. Creating manual help content

7.5.3. Comment—based help

7.5.4. Tags used in documentation comments

7.6. Summary

8. Using and authoring modules

8.1. The role of a module system

8.1.1. Module roles in PowerShell

8.1.2. Module mashups: composing an application

8.2. Module basics

8.2.1. Module terminology

8.2.2. Modules are single—instance objects

8.3. Working with modules

8.3.1. Finding modules on the system

8.3.2. Loading a module

8.3.3. Removing a loaded module

8.4. Writing script modules

8.4.1. A quick review of scripts

8.4.2. Turning a script into a module

8.4.3. Controlling member visibility with Export—ModuleMember

8.4.4. Installing a module

8.4.5. How scopes work in script modules

8.4.6. Nested modules

8.5. Binary modules

8.5.1. Binary modules vs. snap—ins

8.5.2. Creating a binary module

8.5.3. Nesting binary modules in script modules

8.6. Summary

9. Module manifests and metadata

9.1. Module folder structure

9.2. Module manifest structure

9.3. Production manifest elements

9.3.1. Module identity

9.3.2. Runtime dependencies

9.4. Construction manifest elements

9.4.1. The loader manifest elements

9.4.2. Module component load order

9.5. Content manifest elements

9.6. Language restrictions in a manifest

9.7. Advanced module operations

9.7.1. The PSModuleInfo object

9.7.2. Using the PSModuleInfo methods

9.7.3. The defining module versus the calling module

9.7.4. Setting module properties from inside a script module

9.7.5. Controlling when modules can be unloaded

9.7.6. Running an action when a module is removed

9.8. Summary

10. Metaprogramming with scriptblocks and dynamic code

10.1. Scriptblock basics

10.1.1. Invoking commands

10.1.2. Getting CommandInfo objects

10.1.3. The scriptblock literal

10.1.4. Defining functions at runtime

10.2. Building and manipulating objects

10.2.1. Looking at members

10.2.2. Defining synthetic members

10.2.3. Using Add-Member to extend objects

10.2.4. Adding note properties with New-Object

10.3. Using the Select-Object cmdlet

10.4. Dynamic modules

10.4.1. Dynamic script modules

10.4.2. Closures in PowerShell

10.4.3. Creating custom objects from modules

10.5. Steppable pipelines

10.5.1. How steppable pipelines work

10.5.2. Creating a proxy command with steppable pipelines

10.6. A closer look at the type-system plumbing

10.6.1. Adding a property

10.6.2. Shadowing an existing property

10.7. Extending the PowerShell language

10.7.1. Little languages

10.7.2. Type extension

10.8. Building script code at runtime

10.8.1. The Invoke-Expression cmdlet

10.8.2. The ExecutionContext variable

10.8.3. The ExpandString() method

10.8.4. The InvokeScript() method

10.8.5. Mechanisms for creating scriptblocks

10.8.6. Creating functions using the function: drive

10.9. Compiling code with Add-Type

10.9.1. Defining a new .NET class: C#

10.9.2. Defining a new enum at runtime

10.9.3. Dynamic binary modules

10.10. Summary

11. PowerShell remoting

11.1. PowerShell remoting overview

11.1.1. Commands with built-in remoting

11.1.2. The PowerShell remoting subsystem

11.1.3. Enabling remoting

11.1.4. Additional setup steps for workgroup environments

11.1.5. Authenticating the connecting user

11.1.6. Enabling remoting in the enterprise

11.2. Applying PowerShell remoting

11.2.1. Basic remoting examples

11.2.2. Adding concurrency to the examples

11.2.3. Solving a real problem: multi-machine monitoring

11.3. PowerShell remoting sessions and persistent connections

11.3.1. Additional session attributes

11.3.2. Using the New-PSSession cmdlet

11.3.3. Interactive sessions

11.3.4. Managing PowerShell sessions

11.4. Implicit remoting

11.4.1. Using implicit remoting

11.4.2. How implicit remoting works

11.5. Considerations when running commands remotely

11.5.1. Remote session startup directory

11.5.2. Profiles and remoting

11.5.3. Issues running executables remotely

11.5.4. Using files and scripts

11.5.5. Using local variables in remote sessions

11.5.6. Reading and writing to the console

11.5.7. Remote output vs. local output

11.5.8. Processor architecture issues

11.6. Building custom remoting services

11.6.1. Working with custom configurations

11.6.2. Creating a custom configuration

11.6.3. Access controls and endpoints

11.6.4. Constraining a PowerShell session

11.7. Summary

12. PowerShell workflows

12.1. Workflow overview

12.1.1. Why workflows

12.1.2. Workflow Architecture

12.1.3. Your first workflow

12.1.4. Running a workflow

12.1.5. Cmdlets vs. Activities

12.1.6. Workflow restrictions

12.2. Workflow keywords

12.2.1. Parallel

12.2.2. Sequence

12.2.3. InlineScript

12.2.4. Foreach -parallel

12.3. Using workflows effectively

12.3.1. Workflow parameters

12.3.2. Variables in workflows

12.3.3. Nested workflows

12.4. Workflow cmdlets

12.4.1. Workflow execution options

12.4.2. Workflow sessions

12.4.3. Invoking as workflow

12.5. Summary

13. Background jobs

14. Errors and exceptions

14.1. Error handling

14.1.1. ErrorRecords and the error stream

14.1.2. The $error variable and -ErrorVariable parameter

14.1.3. Determining if a command had an error

14.1.4. Controlling the actions taken on an error

14.2. Dealing with errors that terminate execution

14.2.1. The try/catch/finally statement

14.2.2. The throw statement

14.3. PowerShell and the event log

14.3.1. The EventLog cmdlets

14.3.2. Examining the PowerShell event log

14.3.3. Get-WinEvent

14.4. Summary

15. Debugging

15.1. Instrumenting your scripts

15.1.1. The Write cmdlets

15.1.2. Writing Events to the Event Log

15.1.3. Catching errors with strict mode

15.1.4. Static analysis of scripts

15.2. Capturing session output

15.2.1. Starting the transcript

15.2.2. What gets captured in the transcript

15.3. PowerShell script debugging features

15.3.1. The Set-PSDebug cmdlet

15.3.2. Nested prompts and the Suspend operation

15.4. Command line debugging

15.4.1. Working with breakpoint objects

15.4.2. Setting breakpoints on commands

15.4.3. Setting breakpoints on variable assignment

15.4.4. Debugger limitations and issues

15.5. Beyond scripts

15.5.1. Debugging PowerShell jobs

15.5.2. Debugging remote scripts

15.5.3. Debugging PowerShell runspaces

15.6. Summary

16. Working with data

17. Desired State Configuration

18. Classes in PowerShell

19. Programming with PowerShel

About the Technology

Windows PowerShell transformed the way administrators and developers interact with Windows. PowerShell, an elegant dynamic language from Microsoft, lets you script administrative tasks and control Windows from the command line. Because it's a full-featured, first-class Windows programming language, programmers and power-users can now do things in a shell that previously required VB, VBScript, or C#.

What's inside

  • Writing modules and scripts
  • PowerShell Workflows
  • Desired State Configuration
  • PowerShell background jobs
  • PowerShell classes
  • Programming APIs, pipelines and ISE extensions
  • Error handling and debugging

About the reader

Written for developers and administrators with intermediate level scripting knowledge. No prior experience with PowerShell is required.

About the authors

Bruce Payette is a founding member of the PowerShell team at Microsoft. He is co-designer and principal author of the PowerShell language. Richard Siddaway is a multi-year PowerShell MVP, author, speaker and blogger with many years of experience using PowerShell.

Manning Early Access Program (MEAP) Read chapters as they are written, get the finished eBook as soon as it’s ready, and receive the pBook long before it's in bookstores.
Buy
  • MEAP combo $59.99 pBook + eBook
  • MEAP eBook $47.99 pdf + ePub + kindle

FREE domestic shipping on three or more pBooks