Windows PowerShell in Action
Bruce Payette
Foreword by James Truher
  • February 2007
  • ISBN 9781932394900
  • 576 pages
  • printed in black & white
This title is out of print and no longer for sale.

THE book on PowerShell, it has ALL the secrets.

FROM THE FOREWORD by James Truher, Microsoft Corporation

Second edition of this book is available

Windows PowerShell in Action was written by Bruce Payette, one of the founding members of the Windows PowerShell team, co-designer of the PowerShell language and the principal author of the PowerShell language implementation. From him you will gain a deep understanding of the language and how best to use it, and you'll love his insights into why PowerShell works the way it does.

Table of Contents show full

foreword

preface

acknowledgments

about this book

Part 1 Learning PowerShell

1. Welcome to PowerShell

1.1. What is PowerShell?

1.2. Soul of a new language

1.3. Brushing up on objects

1.4. Dude! Where’s my code?

1.5. Summary

2. The basics

2.1. Command concepts and terminology

2.2. Parsing and PowerShell

2.3. Pipelines and commands

2.4. Formatting and output

2.5. Summary

3. Working with types

3.1. Type management in the wild, wild west

3.2. Basic types and literals

3.3. Type conversions

3.4. Summary

4. Operators and expressions

4.1. Arithmetic operators

4.2. The assignment operators

4.3. Comparison operators

4.4. The pattern matching operators

4.5. Logical and bitwise operators

4.6. Summary

5. Advanced operators and variables

5.1. Operators for working with types

5.2. The unary operators

5.3. Grouping, subexpressions, and array subexpressions

5.4. Array operators

5.5. Property and method operators

5.6. The PowerShell format operator -F

5.7. Redirection and the redirection operators

5.8. Variables

5.9. Summary

6. Flow control in scripts

6.1. Using the if/elseif/else statement

6.2. The while loop

6.3. The do/while loop

6.4. The for loop

6.5. The foreach loop

6.6. Labels, break, and continue

6.7. The PowerShell switch statement

6.8. Flow control using cmdlets

6.9. The value of statements

6.10. Summary

7. Functions and scripts

7.1. Function basics

7.2. Formal parameters and the param statement

7.3. Returning values from functions

7.4. Using functions in a pipeline

7.5. Managing functions

7.6. Scripts at long last

7.7. Summary

8. Scriptblocks and objects

8.1. Scriptblock basics

8.2. Building and manipulating objects

8.3. A closer look at the type-system plumbing

8.4. Extending the PowerShell language

8.5. Type extension

8.6. Building code at runtime

8.7. Summary

9. Errors, exceptions, and script debugging

9.1. Error handling

9.2. Dealing with errors that terminate execution

9.3. Script debugging

9.4. Nested prompts and breakpoints

9.5. Low-level tracing

9.6. The PowerShell event log

9.7. Summary

Part 2 Using PowerShell

10. Processing text, files, and XML

10.1. Processing unstructured text

10.2. File processing

10.3. XML processing

10.4. Summary

11. Getting fancy—.NET and WinForms

11.1. Using .NET from PowerShell

11.2. PowerShell and the Internet

11.3. PowerShell and graphical user interfaces

11.4. Summary

12. Windows objects: COM and WMI

12.1. Working with COM in PowerShell

12.2. Working with WMI in PowerShell

12.3. So which object model should I choose?

12.4. Summary

13. Security, security, security

13.1. Introduction to security

13.2. Security modeling

13.3. Securing the PowerShell environment

13.4. Signing scripts

13.5. Writing secure scripts

13.6. Summary

Appendix A: Comparing PowerShell to other languages

Appendix B: Admin Examples

Appendix C: The PowerShell grammar

index

About the Technology

Windows has an easy-to-use interface, but if you want to automate it, life can get hard. That is, unless you use PowerShell, an elegant new dynamic language from Microsoft designed as an all-purpose Windows scripting tool. PowerShell lets you script administrative tasks and control Windows from the command line. Because it was specifically developed for Windows, programmers and power-users can now do things in a shell that previously required VB, VBScript, or C#.

About the book

This book is a tutorial for sysadmins and developers introducing the PowerShell language and its environment. It shows you how to build scripts and utilities to automate system tasks or create powerful system management tools to handle the day-to-day tasks that drive a Windows administrator's life. It's rich in interesting examples that will spark your imagination. The book covers batch scripting and string processing, COM, WMI, and even .NET and WinForms programming.

What's inside

  • Master the PowerShell language
  • Secure scripting with PowerShell
  • How to process strings, files, and XML
  • Techniques for network and GUI programming
  • Script Windows applications like Excel
  • Author feedback at manning.com/payette

About the author

Bruce Payette is a founding member of the PowerShell team at Microsoft. He is a co-designer of the PowerShell language and the principal author of the language implementation. Prior to joining Microsoft, he worked at Softway Systems and MKS, building UNIX tools for Windows.