PowerShell in Depth
An administrator's guide
Don Jones, Richard Siddaway, and Jeffery Hicks
  • February 2013
  • ISBN 9781617290558
  • 632 pages
  • printed in black & white

By three of the best writers in the PowerShell community.

Mike Shepard, Jack Henry & Associates

PowerShell in Depth is the kind of book you'll want open on your desk most of the time. With 40 short chapters, each focused on a specific area of PowerShell, you'll be able to find the answers you need quickly. Each chapter is concise and to-the-point, so you can spend less time reading and more time getting down to the business at hand. It was written by three seasoned PowerShell experts, and every technique has been thoroughly tested. With this book in hand, you'll be able to consistently and quickly produce production quality, maintainable scripts that will save you countless hours of time and effort.

Table of Contents show full

preface

acknowledgments about this book about the authors about the cover illustration

==

==

==

==

Part 1 PowerShell fundamentals

1. Chapter 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. Chapter 2 PowerShell hosts

2.1. -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. Chapter 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. Chapter 4 The basics of PowerShell syntax

4.1. Commands

4.2. Parameters

4.3. Typing trick: line continuation

4.4. Parenthetical commands and expressions

4.5. Script blocks

4.6. Summary

5. Chapter 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.5. Command name conflicts

5.6. Managing module autoloading

5.7. Summary

6. Chapter 6 Operators

6.1. Logical and comparison operators

6.2. Arithmetic operators

6.3. Other operators

6.4. Summary

7. Chapter 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.5. Filtering objects

7.6. Grouping objects

7.7. Measuring objects

7.8. Enumerating objects

7.9. Importing, exporting, and converting objects

7.10. Comparing objects

7.11. Summary

8. Chapter 8 The PowerShell pipeline

8.1. How the pipeline works

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. Chapter 9 Formatting

9.1. The time to format

9.2. The formatting system

9.3. The Format cmdlets

9.4. Eliminating confusion and “gotchas”

9.5. Summary

Part 2 PowerShell management

10. Chapter 10 PowerShell Remoting

10.1. The many forms of remote control

10.2. Remoting overview

10.3. Using Remoting

10.4. PSSessions

10.5. Advanced session techniques

10.6. Creating a custom endpoint

10.7. Connecting to nondefault endpoints

10.8. Enabling the “second hop”

10.9. Setting up WinRM listeners

10.10. Other configuration scenarios

10.11. Implicit Remoting

10.12. Summary

11. Chapter 11 Background jobs and scheduling

11.1. Remoting-based jobs

11.2. WMI jobs

11.3. Scheduled jobs

11.4. Job processes

11.5. Summary

12. Chapter 12 Working with credentials

12.1. About credentials

12.2. Using credentials

12.3. Crazy credentials ideas

12.4. Summary

13. Chapter 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. Chapter 14 Working with HTML and XML data

14.1. Working with HTML

14.2. Working with XML

14.3. Summary

15. Chapter 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.5. Transactional operations

15.6. Every drive is different

15.7. Summary

16. Chapter 16 Variables, arrays, hash tables, and scriptblocks

16.1. 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.6. Scriptblocks

16.7. Summary

17. Chapter 17 PowerShell security

17.1. PowerShell security goals

17.2. PowerShell security mechanisms

17.3. Execution policy

17.4. The PowerShell security debate

17.5. Summary

18. Chapter 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. Chapter 19 PowerShell’s scripting language

19.1. Defining conditions

19.2. Loops: For, Do, While, Until

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. Chapter 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. Chapter 21 Creating objects for output

21.1. Why output objects?

21.2. Syntax for creating custom objects

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. Chapter 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. Chapter 23 PowerShell workflows

23.1. Workflow overview

23.2. Workflow basics

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.8. Running a workflow

23.9. A practical example

23.10. Invoke-AsWorkflow

23.11. PSWorkflowSession

23.12. Troubleshooting a workflow

23.13. Summary

24. Chapter 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. Chapter 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. Chapter 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. Chapter 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.4. A complete example

27.5. Updating type data dynamically

27.6. Get-TypeData

27.7. Remove-TypeData

27.8. Summary

28. Chapter 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. Chapter 29 Writing help

29.1. Comment-based help

29.2. Writing About topics

29.3. XML-based help

29.4. Summary

30. Chapter 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. Chapter 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. Chapter 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.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. Chapter 33 Tips and tricks for creating reports

33.1. What not to do

33.2. Working with HTML fragments and files

33.3. Sending email

33.4. Summary

Part 4 Advanced PowerShell

34. Chapter 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. Chapter 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. Chapter 36 Accessing databases

36.1. Native SQL vs. OLEDB

36.2. Connecting to data sources

36.3. Querying data

36.4. Adding, changing, and deleting data

36.5. Calling stored procedures

36.6. A module to make it easier

36.7. Summary

37. Chapter 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. Chapter 38 Building a GUI

38.1. WinForms via PowerShell Studio

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. Chapter 39 WMI and CIM

39.1. What is WMI?

39.2. WMI cmdlets

39.3. CIM cmdlets

39.4. CIM sessions

39.5. “Cmdlets over objects”

39.6. Summary

40. Chapter 40 Best practices

40.1. PowerShell general best practices

40.2. PowerShell scripting best practices

40.3. PowerShell in the enterprise best practices

© 2014 Manning Publications Co.

About the Technology

PowerShell is part of nearly everything a Windows administrator touches, and the soon-to-be-released version 3 adds still more powerful features for you to learn and use. With PowerShell you can securely and efficiently automate almost every aspect of your Windows system and servers.

About the book

Organized into 40 concise chapters, PowerShell in Depth is the go-to reference for administrators working with Windows PowerShell. Every major shell technique, technology, and tactic is explained and demonstrated, providing a comprehensive reference to almost everything an admin would do in the shell. Written by three experienced authors and PowerShell MVPs, this is the PowerShell book you'll keep next to your monitor—not on your bookshelf!

This book requires basic familiarity with PowerShell.

What's inside

  • Covers PowerShell 3.0
  • Automating time-consuming tasks
  • Managing HTML and XML data
  • Background jobs and scheduling
  • PowerShell security
  • Packaging and deploying scripts
  • Standard scripting conventions
  • Using the .NET Framework in PowerShell scripts
  • Much more

About the author

Don Jones, Jeffery Hicks, and Richard Siddaway are Microsoft MVPs who have collectively authored nearly three dozen books on PowerShell and Windows administration.


combo $49.99 pBook + eBook
eBook $39.99 pdf + ePub + kindle

FREE domestic shipping on three or more pBooks

A most wonderful Power-Shell administrators’ guide.

Kais Ayari, Microsof

Hicks, Jones, and Siddaway come together to deliver the ultimate PowerShell resource.

James Berkenbile, Berkenbile Consulting

I have many books on my shelf—this one will be on my desk!

Trent Whiteley, Fiserv