Learn Windows PowerShell in a Month of Lunches, Second Edition
Don Jones and Jeffery D. Hicks
  • November 2012
  • ISBN 9781617291081
  • 368 pages
  • printed in black & white

Extremely useful as a tutorial and a reference!

Bennett Scharf, MountainView Servicing Group


Learn Windows PowerShell in a Month of Lunches, Third Edition is now available. An eBook of this older edition is included at no additional cost when you buy the revised edition!

A limited number of pBook copies of this edition are still available. Please contact Manning Support to inquire about purchasing previous edition copies.

Learn Windows PowerShell in a Month of Lunches, Second Edition is an innovative tutorial designed for administrators. Just set aside one hour a day—lunchtime would be perfect—for a month, and you'll be automating Windows tasks faster than you ever thought possible. You'll start with the basics—what is PowerShell and what can you do with it. Then, you'll move systematically through the techniques and features you'll use to make your job easier and your day shorter.

Table of Contents detailed table of contents


about this book

author online

about the authors


1. Before you begin

1.1. Why you can’t afford to ignore PowerShell

1.2. Is this book for you?

1.3. How to use this book

1.4. Setting up your lab environment

1.5. Installing Windows PowerShell

1.6. Online resources

1.7. Being immediately effective with PowerShell

2. Meet PowerShell

2.1. Choose your weapon

2.2. It’s typing class all over again

2.3. Common points of confusion

2.4. What version is this?

2.5. Lab

2.6. Further exploration

3. Using the help system

3.1. The help system: how you discover commands

3.2. Updatable help

3.3. Asking for help

3.4. Using help to find commands

3.5. Interpreting the help

3.6. Accessing "about" topics

3.7. Accessing online help

3.8. Lab

4. Running commands

4.1. Not scripting, but running commands

4.2. The anatomy of a command

4.3. The cmdlet naming convention

4.4. Aliases: nicknames for commands

4.5. Taking shortcuts

4.6. Cheating, a bit: Show-Command

4.7. Support for external commands

4.8. Dealing with errors

4.9. Common points of confusion

4.10. Lab

5. Working with providers

5.1. What are providers?

5.2. How the filesystem is organized

5.3. How the filesystem is like other data stores

5.4. Navigating the filesystem

5.5. Using wildcards and literal paths

5.6. Working with other providers

5.7. Lab

5.8. Further exploration

6. The pipeline: connecting commands

6.1. Connect one command to another: less work for you

6.2. Exporting to a CSV or an XML file

6.3. Piping to a file or a printer

6.4. Converting to HTML

6.5. Using cmdlets that modify the system: killing processes and stopping services

6.6. Common points of confusion

6.7. Lab

7. Adding commands

7.1. How one shell can do everything

7.2. About product-specific "management shells"

7.3. Extensions: finding and adding snap-ins

7.4. Extensions: finding and adding modules

7.5. Command conflicts and removing extensions

7.6. Playing with a new module

7.7. Profile scripts: preloading extensions when the shell starts

7.8. Common points of confusion

7.9. Lab

8. Objects: data by another name

8.1. What are objects?

8.2. Why PowerShell uses objects

8.3. Discovering objects: Get-Member

8.4. Object attributes, or "properties"

8.5. Object actions, or "methods"

8.6. Sorting objects

8.7. Selecting the properties you want

8.8. Objects until the end

8.9. Common points of confusion

8.10. Lab

9. The pipeline, deeper

9.1. The pipeline: enabling power with less typing

9.2. How PowerShell passes data down the pipeline

9.3. Plan A: pipeline input ByValue

9.4. Plan B: pipeline input ByPropertyName

9.5. When things don’t line up: custom properties

9.6. Parenthetical commands

9.7. Extracting the value from a single property

9.8. Lab

9.9. Further exploration

10. Formatting—and why it’s done on the right

10.1. Formatting: making what you see prettier

10.2. About the default formatting

10.3. Formatting tables

10.4. Formatting lists

10.5. Formatting wide

10.6. Custom columns and list entries

10.7. Going out: to a file, a printer, or the host

10.8. Another out: GridViews

10.9. Common points of confusion

10.10. Lab

10.11. Further exploration

11. Filtering and comparisons

11.1. Making the shell give you just what you need

11.2. Filter left

11.3. Comparison operators

11.4. Filtering objects out of the pipeline

11.5. The iterative command-line model

11.6. Common points of confusion

11.7. Lab

11.8. Further exploration

12. A practical interlude

12.1. Defining the task

12.2. Finding the commands

12.3. Learning to use the commands

12.4. Tips for teaching yourself

12.5. Lab

13. Remote control: one to one, and one to many

13.1. The idea behind remote PowerShell

13.2. WinRM overview

13.3. Using Enter-PSSession and Exit-PSSession for one-to-one remoting

13.4. Using Invoke-Command for one-to-many remoting

13.5. Differences between remote and local commands

13.6. But wait, there’s more

13.7. Remote options

13.8. Common points of confusion

13.9. Lab

13.10. Further exploration

14. Using Windows Management Instrumentation

14.1. WMI essentials

14.2. The bad news about WMI

14.3. Exploring WMI

14.4. Choose your weapon: WMI or CIM

14.5. Using Get-WmiObject

14.6. Using Get-CimInstance

14.7. WMI documentation

14.8. Common points of confusion

14.9. Lab

14.10. Further exploration

15. Multitasking with background jobs

15.1. Making PowerShell do multiple things at the same time

15.2. Synchronous versus asynchronous

15.3. Creating a local job

15.4. WMI, as a job

15.5. Remoting, as a job

15.6. Getting job results

15.7. Working with child jobs

15.8. Commands for managing jobs

15.9. Scheduled jobs

15.10. Common points of confusion

15.11. Lab

16. Working with many objects, one at a time

16.1. Automation for mass management

16.2. The preferred way: "batch" cmdlets

16.3. The WMI way: invoking WMI methods

16.4. The backup plan: enumerating objects

16.5. Common points of confusion

16.6. Lab

17. Security alert!

17.1. Keeping the shell secure

17.2. Windows PowerShell security goals

17.3. Execution policy and code signing

17.4. Other security measures

17.5. Other security holes?

17.6. Security recommendations

17.7. Lab

18. Variables: a place to store your stuff

18.1. Introduction to variables

18.2. Storing values in variables

18.3. Using variables: fun tricks with quotes

18.4. Storing many objects in a variable

18.5. More tricks with double quotes

18.6. Declaring a variable’s type

18.7. Commands for working with variables

18.8. Variable best practices

18.9. Common points of confusion

18.10. Lab

18.11. Further exploration

19. Input and output

19.1. Prompting for, and displaying, information

19.2. Read-Host

19.3. Write-Host

19.4. Write-Output

19.5. Other ways to write

19.6. Lab

19.7. Further exploration

20. Sessions: remote control with less work

20.1. Making PowerShell remoting a bit easier

20.2. Creating and using reusable sessions

20.3. Using sessions with Enter-PSSession

20.4. Using sessions with Invoke-Command

20.5. Implicit remoting: importing a session

20.6. Disconnected sessions

20.7. Lab

20.8. Further exploration

21. You call this scripting?

21.1. Not programming, more like batch files

21.2. Making commands repeatable

21.3. Parameterizing commands

21.4. Creating a parameterized script

21.5. Documenting your script

21.6. One script, one pipeline

21.7. A quick look at scope

21.8. Lab

22. Improving your parameterized script

22.1. Starting point

22.2. Getting PowerShell to do the hard work

22.3. Making parameters mandatory

22.4. Adding parameter aliases

22.5. Validating parameter input

22.6. Adding the warm and fuzzies with verbose output

22.7. Lab

23. Advanced remoting configuration

23.1. Using other endpoints

23.2. Creating custom endpoints

23.3. Enabling multihop remoting

23.4. Digging deeper into remoting authentication

23.5. Lab

24. Using regular expressions to parse text files

24.1. The purpose of regular expressions

24.2. A regex syntax primer

24.3. Using regex with -Match

24.4. Using regex with Select-String

24.5. Lab

24.6. Further exploration

25. Additional random tips, tricks, and techniques

25.1. Profiles, prompts, and colors: customizing the shell

25.2. Operators: -as, -is, -replace, -join, -split, -in, -contains

25.3. String manipulation

25.4. Date manipulation

25.5. Dealing with WMI dates

25.6. Setting default parameter values

25.7. Playing with script blocks

25.8. More tips, tricks, and techniques

26. Using someone else’s script

26.1. The script

26.2. It’s a line-by-line examination

26.3. Lab

27. Never the end

27.1. Ideas for further exploration

27.2. "Now that I’ve read the book, where do I start?"

27.3. Other resources you’ll grow to love

28. PowerShell cheat sheet

28.1. Punctuation

28.2. Help file

28.3. Operators

28.4. Custom property and column syntax

28.5. Pipeline parameter input

28.6. When to use $_

appendix: Review labs


About the Technology

PowerShell is both a language and an administrative shell with which you can control and automate nearly every aspect of Windows. It accepts and executes commands immediately, and you can write scripts to manage most Windows servers like Exchange, IIS, and SharePoint.

About the book

This book is a tutorial designed for busy administrators. Just set aside one hour a day for a month and you'll learn all the practical techniques you need to make your job easier and your day shorter. This totally revised book covers new PowerShell features that run on Windows 7, Windows Server 2008 R2, and later. This edition is appropriate for PowerShell version 3 and later.

What's inside

  • Learn PowerShell from the beginning—no experience required!
  • Covers PowerShell 3 and later running on Windows 7, Windows Server 2008 R2, and later
  • Each lesson should take you one hour or less

About the reader

Experience with Windows administration is helpful. No programming experience is assumed.

About the authors

Powershell MVPs Don Jones and Jeffery Hicks bring years as successful trainers to this concise, easy-to-follow book. Don blogs at PowerShell.com and you can find Jeff at jdhitsolutions.com/blog.

combo $44.99 pBook + eBook

FREE domestic shipping on three or more pBooks

This second edition is even better than the first—a must-have.

David Moravec, PowerShell.cz

Get up to speed quickly!

Keith Hill, Windows PowerShell MVP Technologies

Learning PowerShell made easy.

Rajesh Attaluri, nvestec