You are previewing Learn PowerShell Toolmaking in a Month of Lunches.
O'Reilly logo
Learn PowerShell Toolmaking in a Month of Lunches

Book Description

Summary

Packed with hands-on labs to reinforce what you're learning, Learn PowerShell Toolmaking in a Month of Lunches is the best way to learn PowerShell scripting and toolmaking. Just set aside one hour a day—lunchtime would be perfect—for each self-contained lesson. You'll move quickly through core scripting concepts and start working on four real-world, practical tools. Each chapter adds more functionality, including custom formatting, error handling, parameterized input, input validation, help files and documentation, and more.

About this Book

You don’t have to be a software developer to build PowerShell tools. With this book, a PowerShell user is a step away from becoming a proficient toolmaker.

Learn PowerShell Toolmaking in a Month of Lunches is the best way to learn PowerShell scripting and toolmaking in just one hour a day. It’s packed with hands-on labs to reinforce what you’re learning. It’s an easy-to-follow guide that covers core scripting concepts using four practical examples. Each chapter builds on the previous one as you add custom formatting, error handling, input validation, help files, and more.

What's Inside

  • Build your own administrative tools

  • Learn by doing with hands-on labs

  • Make scripts that feel like native PowerShell cmdlets

  • This book does not assume you are a programmer. Experience using PowerShell as a command-line interface is helpful but not required.

    About the Authors

    Don Jones is a PowerShell MVP, speaker, and trainer. Jeffery Hicks is a PowerShell MVP and an independent consultant, trainer, and author. Don and Jeff coauthored Learn Windows PowerShell 3 in a Month of Lunches, Second Edition (Manning 2012) and PowerShell in Depth (Manning 2013).

    Table of Contents

    1. Copyright
    2. Brief Table of Contents
    3. Table of Contents
    4. Preface
    5. About this Book
      1. Author Online
    6. About the Authors
    7. Acknowledgments
    8. Part 1. Introduction to toolmaking
      1. Chapter 1. Before you begin
        1. 1.1. What is toolmaking?
        2. 1.2. Is this book for you?
        3. 1.3. Prerequisites
        4. 1.4. How to use this book
      2. Chapter 2. PowerShell scripting overview
        1. 2.1. What is PowerShell scripting?
        2. 2.2. PowerShell’s execution policy
        3. 2.3. Running scripts
        4. 2.4. Editing scripts
        5.  2.5. Further exploration: script editors
        6. 2.6. Lab
      3. Chapter 3. PowerShell’s scripting language
        1. 3.1. One script, one pipeline
        2. 3.2. Variables
        3.  3.3. Quotation marks
        4. 3.4. Object members and variables
        5. 3.5. Parentheses
        6. 3.6. Refresher: comparisons
        7. 3.7. Logical constructs
        8. 3.8. Looping constructs
        9. 3.9. Break and Continue in constructs
        10. 3.10. Lab
      4. Chapter 4. Simple scripts and functions
        1. 4.1. Start with a command
        2. 4.2. Turn the command into a script
        3.  4.3. Parameterize the command
        4.  4.4. Turn the script into a function
        5. 4.5. Testing the function
        6. 4.6. Lab
      5. Chapter 5. Scope
        1. 5.1. What is scope?
        2. 5.2. Seeing scope in action
        3. 5.3. Working out of scope
        4.  5.4. Getting strict with scope
        5. 5.5. Best practices for scope
        6. 5.6. Lab
    9. Part 2. Building an inventory tool
      1. Chapter 6. Tool design guidelines
        1. 6.1. Do one thing, and do it well
        2. 6.2. Labs
      2. Chapter 7. Advanced functions, part 1
        1. 7.1. Advanced function template
        2. 7.2. Designing the function
        3. 7.3. Declaring parameters
        4. 7.4. Testing the parameters
        5. 7.5. Writing the main code
        6. 7.6. Outputting custom objects
        7.  7.7. What not to do
        8.  7.8. Coming up next
        9. 7.9. Labs
      3. Chapter 8. Advanced functions, part 2
        1. 8.1. Making parameters mandatory
        2. 8.2. Verbose output
        3.  8.3. Parameter aliases
        4. 8.4. Accepting pipeline input
        5. 8.5. Parameter validation
        6. 8.6. Adding a switch parameter
        7. 8.7. Parameter help
        8. 8.8. Coming up next
        9. 8.9. Labs
      4. Chapter 9. Writing help
        1. 9.1. Comment-based help
        2.  9.2. XML-based help
        3. 9.3. Coming up next
        4. 9.4. Labs
      5. Chapter 10. Error handling
        1. 10.1. It’s all about the action
        2. 10.2. Setting the error action
        3. 10.3. Saving the error
        4. 10.4. Error handling v1: Trap
        5. 10.5. Error Handling v2+: Try...Catch...Finally
        6.  10.6. Providing some visuals
        7.  10.7. Coming up next
        8. 10.8. Labs
      6. Chapter 11. Debugging techniques
        1. 11.1. Two types of bugs
        2. 11.2. Solving typos
        3. 11.3. The real trick to debugging: expectations
        4. 11.4. Dealing with logic errors: trace code
        5. 11.5. Dealing with logic errors: breakpoints
        6. 11.6. Seriously, have expectations
        7. 11.7. Coming up next
        8. 11.8. Lab
      7. Chapter 12. Creating custom format views
        1. 12.1. The anatomy of a view
        2. 12.2. Adding a type name to output objects
        3.  12.3. Making a view
        4. 12.4. Loading and debugging the view
        5.  12.5. Using the view
        6. 12.6. Coming up next
        7. 12.7. Labs
      8. Chapter 13. Script and manifest modules
        1. 13.1. Introducing modules
        2.  13.2. Creating a script module
        3. 13.3. Creating a module manifest
        4.  13.4. Creating a module-level setting variable
        5. 13.5. Coming up next
        6. 13.6. Lab
      9. Chapter 14. Adding database access
        1. 14.1. Simplifying database access
        2. 14.2. Setting up your environment
        3. 14.3. The database functions
        4.  14.4. About the database functions
        5. 14.5. Using the database functions
        6. 14.6. Lab
      10. Chapter 15. Interlude: creating a new tool
        1.  15.1. Designing the tool
        2. 15.2. Writing and testing the function
        3. 15.3. Dressing up the parameters
        4. 15.4. Adding help
        5. 15.5. Handling errors
        6. 15.6. Making a module
        7. 15.7. Coming up next
    10. Part 3. Advanced toolmaking techniques
      1. Chapter 16. Making tools that make changes
        1.  16.1. The –Confirm and –WhatIf parameters
        2. 16.2. Passthrough ShouldProcess
        3. 16.3. Defining the impact level
        4. 16.4. Implementing ShouldProcess
        5.  16.5. Lab
      2. Chapter 17. Creating a custom type extension
        1. 17.1. The anatomy of an extension
        2. 17.2. Creating a script property
        3.  17.3. Creating a script method
        4. 17.4. Loading the extension
        5. 17.5. Testing the extension
        6. 17.6. Adding the extension to a manifest
        7. 17.7. Lab
      3. Chapter 18. Creating PowerShell workflows
        1. 18.1. Workflow overview
        2. 18.2. General workflow design strategy
        3. 18.3. Example workflow scenario
        4.  18.4. Writing the workflow
        5. 18.5. Workflows vs. functions
        6. 18.6. Lab
      4. Chapter 19. Troubleshooting pipeline input
        1. 19.1. Refresher: how pipeline input works
        2. 19.2. Introducing Trace-Command
        3. 19.3. Interpreting trace-command output
        4. 19.4. Lab
      5. Chapter 20. Using object hierarchies for complex output
        1. 20.1. When a hierarchy might be necessary
        2. 20.2. Hierarchies and CSV: not a good idea
        3. 20.3. Creating nested objects
        4. 20.4. Working with nested objects
        5. 20.5. Lab
      6. Chapter 21. Globalizing a function
        1. 21.1. Introduction to globalization
        2. 21.2. PowerShell’s data language
        3. 21.3. Storing translated strings
        4.  21.4. Do you need to globalize?
        5. 21.5. Lab
      7. Chapter 22. Crossing the line: utilizing the .NET Framework
        1. 22.1. .NET classes and instances
        2. 22.2. Static methods of a class
        3. 22.3. Instantiating a class
        4. 22.4. Using Reflection
        5. 22.5. Finding class documentation
        6. 22.6. PowerShell vs. Visual Studio
        7. 22.7. Lab
    11. Part 4. Creating tools for delegated administration
      1. Chapter 23. Creating a GUI tool, part 1: the GUI
        1. 23.1. Introduction to WinForms
        2. 23.2. Using a GUI to create the GUI
        3. 23.3. Manually coding the GUI
        4. 23.4. Showing the GUI
        5.  23.5. Lab
      2. Chapter 24. Creating a GUI tool, part 2: the code
        1. 24.1. Addressing GUI objects
        2. 24.2. Example: text boxes
        3. 24.3. Example: button clicks
        4. 24.4. Example: list boxes
        5.  24.5. Example: radio buttons
        6. 24.6. Example: check boxes
        7.  24.7. Lab
      3. Chapter 25. Creating a GUI tool, part 3: the output
        1. 25.1. Using Out-GridView
        2. 25.2. Creating a form for output
        3. 25.3. Populating and showing the output
        4.  25.4. Lab
      4. Chapter 26. Creating proxy functions
        1. 26.1. What are proxy functions?
        2. 26.2. Creating the proxy function template
        3. 26.3. Removing a parameter
        4. 26.4. Adding a parameter
        5. 26.5. Loading the proxy function
        6. 26.6. Lab
      5. Chapter 27. Setting up constrained remoting endpoints
        1. 27.1. Refresher: Remoting architecture
        2. 27.2. What are constrained endpoints?
        3. 27.3. Creating the endpoint definition
        4. 27.4. Registering the endpoint
        5. 27.5. Connecting to the endpoint
        6.  27.6. Lab
      6. Chapter 28. Never the end
        1. 28.1. Welcome to toolmaking
        2. 28.2. Cool ideas for tools
        3. 28.3. What’s your next step?
    12. Appendix. GUI technologies and PowerShell
      1. A.1. WinForms vs. WPF
      2. A.2. PrimalForms / PowerShell Studio
      3. A.3. Other options
    13. Index
    14. List of Figures
    15. List of Tables
    16. List of Listings