contents

preface
acknowledgments
about this book
about the authors
about the cover illustration

Part 1 PowerShell fundamentals

Chapter 1 Introduction
Who this book is for
What this book will teach you
What this book won’t teach you
Where we drew the line
Beyond PowerShell
Ready?
Chapter 2 PowerShell hosts
32-bit vs. 64-bit, and administrator vs. not
The console
The PowerShell ISE
Command history buffer vs. PowerShell’s history
Transcripts
Summary
Chapter 3 Using the PowerShell help system
The help commands
Where’s the help?
Using the help
“About” help files
Provider help
Interpreting command help
Common parameters
Summary
Chapter 4 The basics of PowerShell syntax
Commands
Parameters
Typing trick: line continuation
Parenthetical commands and expressions
Script blocks
Summary
Chapter 5 Working with PSSnapins and modules
There’s only one shell
PSSnapins vs. modules
Loading, autoloading, and profiles
Using extensions
Command name conflicts
Managing module autoloading
Summary
Chapter 6 Operators
Logical and comparison operators
Arithmetic operators
Other operators
Summary
Chapter 7 Working with objects
Introduction to objects
Members: properties, methods, and events
Sorting objects
Selecting objects
Filtering objects
Grouping objects
Measuring objects
Enumerating objects
Importing, exporting, and converting objects
Comparing objects
Summary
Chapter 8 The PowerShell pipeline
How the pipeline works
Parameter binding ByValue
Pipeline binding ByPropertyName
Troubleshooting parameter binding
When parameter binding lets you down
The pipeline with external commands
Summary
Chapter 9 Formatting
The time to format
The formatting system
The Format cmdlets
Eliminating confusion and “gotchas”
Summary

Part 2 PowerShell management

Chapter 10 PowerShell Remoting
The many forms of remote control
Remoting overview
Using Remoting
PSSessions
Advanced session techniques
Creating a custom endpoint
Connecting to nondefault endpoints
Enabling the “second hop”
Setting up WinRM listeners
Other configuration scenarios
Implicit Remoting
Summary
Chapter 11 Background jobs and scheduling
Remoting-based jobs
WMI jobs
Scheduled jobs
Job processes
Summary
Chapter 12 Working with credentials
About credentials
Using credentials
Crazy credentials ideas
Summary
Chapter 13 Regular expressions
Basic regular expression syntax
The –match operator
The select-string cmdlet
Switch statement
The REGEX object
Summary
Chapter 14 Working with HTML and XML data
Working with HTML
Working with XML
Summary
Chapter 15 PSDrives and PSProviders
Why use PSProviders?
What are PSProviders?
What are PSDrives?
Working with PSDrives
Transactional operations
Every drive is different
Summary
Chapter 16 Variables, arrays, hash tables, and scriptblocks
Variables
Built-in variables and the Variable: drive
Variable commands
Arrays
Hash tables and ordered hash tables
Scriptblocks
Summary
Chapter 17 PowerShell security
PowerShell security goals
PowerShell security mechanisms
Execution policy
The PowerShell security debate
Summary
Chapter 18 Advanced PowerShell syntax
Splatting
Defining default parameter values
Running external utilities
Expressions in quotes: $($cool)
Parentheticals as objects
Increase the format enumeration limit
Hash tables as objects
Summary

Part 3 PowerShell scripting and automation

Chapter 19 PowerShell’s scripting language
Defining conditions
Loops: For, Do, While, Until
ForEach
Break and Continue
If . . . ElseIf . . . Else
Switch
Mastering the punctuation
Summary
Chapter 20 Basic scripts and functions
Script or function?
Execution lifecycle and scope
Starting point: a command
Accepting input
Creating output
“Filtering” scripts
Moving to a function
Summary
Chapter 21 Creating objects for output
Why output objects?
Syntax for creating custom objects
Complex objects: collections as properties
Applying a type name to custom objects
So, why bother?
Summary
Chapter 22 Scope
Understanding scope
Observing scope in action
Dot sourcing
Manipulating cross-scope elements
Being private
Being strict
Summary
Chapter 23 PowerShell workflows
Workflow overview
Workflow basics
General workflow design strategy
Example workflow scenario
Writing the workflow
Workflows vs. functions
Specific workflow techniques
Running a workflow
A practical example
Invoke-AsWorkflow
PSWorkflowSession
Troubleshooting a workflow
Summary
Chapter 24 Advanced syntax for scripts and functions
Starting point
Advanced parameters
Variations on parameter inputs
Parameter aliases
Parameter validation
Parameter sets
WhatIf and Confirm parameters
Verbose output
Summary
Chapter 25 Script modules and manifest modules
Making a script module
Exporting module members
Making a module manifest
Creating dynamic modules
Summary
Chapter 26 Custom formatting views
Object type names
Getting view templates
Starting a view file
Adding view types
Importing view data
Using named views
Going further
Summary
Chapter 27 Custom type extensions
What are type extensions?
Creating and loading a type extension file
Making type extensions
A complete example
Updating type data dynamically
Get-TypeData
Remove-TypeData
Summary
Chapter 28 Data language and internationalization
Internationalization basics
Adding a data section
Storing translated strings
Testing localization
Summary
Chapter 29 Writing help
Comment-based help
Writing About topics
XML-based help
Summary
Chapter 30 Error handling techniques
About errors and exceptions
Using $ErrorActionPreference and –ErrorAction
Using –ErrorVariable
Using $Error
Trap constructs
Try...Catch...Finally constructs
Summary
Chapter 31 Debugging tools and techniques
Debugging: all about expectations
Write-Debug
Breakpoints
Using Set-PSDebug
Debugging in third-party editors
Summary
Chapter 32 Functions that work like cmdlets
Defining the task
Building the command
Parameterizing the pipeline
Adding professional features
Error handling
Making it a function and adding help
Creating a custom view
Creating a type extension
Making a module manifest
Summary
Chapter 33 Tips and tricks for creating reports
What not to do
Working with HTML fragments and files
Sending email
Summary

Part 4 Advanced PowerShell

Chapter 34 Working with the Component Object Model (COM)
Introduction to COM objects
Instantiating COM objects in PowerShell
Accessing and using COM objects’ members
PowerShell and COM examples
Summary
Chapter 35 Working with .NET Framework objects
Classes, instances, and members
.NET Framework syntax in PowerShell
.NET support in PowerShell
Accessing static members
Finding the right framework bits
Creating and working with instances
Summary
Chapter 36 Accessing databases
Native SQL vs. OLEDB
Connecting to data sources
Querying data
Adding, changing, and deleting data
Calling stored procedures
A module to make it easier
Summary
Chapter 37 Proxy functions
The purpose of proxy functions
How proxy functions work
Creating a basic proxy function
Adding a parameter
Removing a parameter
Turning it into a function
Summary
Chapter 38 Building a GUI
WinForms via PowerShell Studio
Windows Presentation Foundation (WPF) and ShowUI
WinForms vs. WPF
Ideas for leveraging a GUI tool
Summary
Chapter 39 WMI and CIM
What is WMI?
WMI cmdlets
CIM cmdlets
CIM sessions
“Cmdlets over objects”
Summary
Chapter 40 Best practices
PowerShell general best practices
PowerShell scripting best practices
PowerShell in the enterprise best practices

          index