liveBook · Manning

What you will learn in Learn PowerShell Scripting in a Month of Lunches, Second Edition: Write and organize scripts and tools

Write and organize scripts and tools

by James Petty,Don Jones,Jeffery Hicks

Chapter by chapter

Chapter 1: Before you begin

1.1 What is toolmaking? · 1.2 Is this book for you? · 1.3 What you need for this book · 1.3.1 PowerShell version · 1.3.2 Administrative privileges · 1.3.3 Script editor · 1.4 How to use this book · 1.5 Expectations · 1.6 How to ask for help · 1.7 Summary

What you learn in chapter 1 →

Chapter 2: Setting up your scripting environment

2.1 The operating system · 2.2 PowerShell · 2.3 Administrative privileges and execution policy · 2.4 Script editors · 2.5 Our lab environment · 2.6 Example code · 2.7 Your turn · 2.8 Summary

What you learn in chapter 2 →

Chapter 3: WWPD: What would PowerShell do?

3.1 One tool, one task · 3.2 Naming your tools · 3.3 Naming parameters · 3.4 Producing output · 3.5 Don’t assume · 3.6 Avoid innovation · 3.7 Summary

What you learn in chapter 3 →

Chapter 4: Review: Parameter binding and the PowerShell pipeline

4.1 The operating system · 4.2 It’s all in the parameters · 4.3 Pipeline: ByValue · 4.3.1 Introducing Trace-Command · 4.3.2 Tracing the ByValue parameter binding · 4.3.3 When ByValue fails · 4.4 ByPropertyName · 4.4.1 Let’s trace ByPropertyName · 4.4.2 When ByPropertyName fails · 4.4.3 Planning ahead · 4.5 Summary

What you learn in chapter 4 →

Chapter 5: Scripting language: A crash course

5.1 Comparisons · 5.1.1 Wildcards · 5.1.2 Collections · 5.1.3 Troubleshooting comparisons · 5.2 The If construct · 5.3 The ForEach construct · 5.4 The Switch construct · 5.5 The Do/While construct · 5.6 The For construct · 5.7 Break · 5.8 Summary

What you learn in chapter 5 →

Chapter 6: The many forms of scripting (and which to choose)

6.1 Tools vs. controllers · 6.2 Thinking about tools · 6.3 Thinking about controllers · 6.4 Comparing tools and controllers · 6.5 Some concrete examples · 6.5.1 Emailing users whose passwords are about to expire · 6.5.2 Provisioning new users · 6.5.3 Setting file permissions · 6.5.4 Helping the help desk · 6.6 Control more · 6.7 Lab · 6.8 Summary

What you learn in chapter 6 →

Chapter 7: Scripts and security

7.1 Security is number one · 7.2 Execution policy · 7.2.1 Execution scope · 7.2.2 Getting your policies · 7.2.3 Setting an execution policy · 7.3 PowerShell isn’t the default application · 7.4 Running scripts · 7.5 Recommendations · 7.6 Summary

What you learn in chapter 7 →

Chapter 8: Always design first

8.1 Tools do one thing · 8.2 Tools are testable · 8.3 Tools are flexible · 8.4 Tools look native · 8.5 For example · 8.6 Your turn · 8.6.1 Start here · 8.6.2 Your task · 8.6.3 Our take · 8.7 Summary

What you learn in chapter 8 →

Chapter 9: Avoiding bugs: Start with a command

9.1 What you need to run · 9.2 Breaking it down, and running it right · 9.3 Running commands and digging deeper · 9.4 Process matters · 9.5 Know what you need · 9.6 Your turn · 9.6.1 Start here · 9.6.2 Your task · 9.6.3 Our take · 9.7 Summary

What you learn in chapter 9 →

Chapter 10: Building a basic function and script module

10.1 Starting with a basic function · 10.1.1 Designing the input parameters · 10.1.2 Writing the code · 10.1.3 Designing the output · 10.2 Creating a script module · 10.3 Prereq check · 10.4 Running the command · 10.5 Your turn · 10.5.1 Start here · 10.5.2 Your task · 10.5.3 Our take · 10.6 Summary

What you learn in chapter 10 →

Chapter 11: Getting started with advanced functions

11.1 About CmdletBinding and common parameters · 11.1.1 Accepting pipeline input · 11.1.2 Mandatory-ness · 11.1.3 Parameter validation · 11.1.4 Parameter aliases · 11.1.5 Supporting –Confirm and –WhatIf · 11.2 Your turn · 11.2.1 Start here · 11.2.2 Your task · 11.2.3 Our take · 11.3 Summary

What you learn in chapter 11 →

Chapter 12: Objects: The best kind of output

12.1 Assembling the information · 12.2 Constructing and emitting output · 12.3 A quick test · 12.4 An object alternative · 12.5 Enriching objects · 12.6 Your turn · 12.6.1 Start here · 12.6.2 Your task · 12.6.3 Our take · 12.7 Summary

What you learn in chapter 12 →

Chapter 13: Using all the streams

13.1 Knowing the seven output streams · 13.2 Adding verbose and warning output · 13.3 Doing more with -Verbose · 13.4 Information output · 13.4.1 A detailed Information stream example · 13.5 Your turn · 13.5.1 Start here · 13.5.2 Your task · 13.5.3 Our take · 13.6 Summary

What you learn in chapter 13 →

Chapter 14: Simple help: Making a comment

14.1 Where to put your help · 14.2 Getting started · 14.3 Going further with comment-based help · 14.4 Broken help · 14.5 Beyond comments · 14.6 Your turn · 14.6.1 Start here · 14.6.2 Your task · 14.6.3 Our take · 14.7 Summary

What you learn in chapter 14 →

Chapter 15: Errors and how to deal with them

15.1 Understanding errors and exceptions · 15.2 Bad handling · 15.3 Two reasons for exception handling · 15.4 Handling exceptions in your tool · 15.5 Capturing the exception · 15.6 Handling exceptions for non-commands · 15.7 Going further with exception handling · 15.8 Your turn · 15.8.1 Start here · 15.8.2 Your task · 15.8.3 Our take · 15.9 Summary

What you learn in chapter 15 →

Chapter 16: Filling out a manifest

16.1 Module execution order · 16.2 Creating a new manifest · 16.3 Examining the manifest · 16.3.1 Metadata · 16.3.2 The root module · 16.3.3 Prerequisites · 16.3.4 Scripts, types, and formats · 16.3.5 Exporting members · 16.4 Your turn · 16.4.1 Start here · 16.4.2 Your task · 16.4.3 Our take · 16.5 Summary

What you learn in chapter 16 →

Chapter 17: Changing your brain when it comes to scripting

17.1 Example 1 · 17.1.1 The critique · 17.1.2 Our take · 17.1.3 Thinking beyond the literal · 17.2 Example 2 · 17.2.1 The walkthrough · 17.2.2 Our take · 17.3 Your turn · 17.3.1 Start here · 17.3.2 Your task · 17.3.3 Our take · 17.4 Summary

What you learn in chapter 17 →

Chapter 18: Professional-grade scripting

18.1 Using source control · 18.2 Code clarity · 18.3 Effective comments · 18.4 Formatting your code · 18.5 Meaningful variable names · 18.6 Avoiding aliases · 18.7 Logic over complexity · 18.8 Providing help · 18.9 Avoiding Write-Host and Read-Host · 18.10 Sticking with single quotes · 18.11 Not polluting the global scope · 18.12 Being flexible · 18.13 Prioritizing security · 18.14 Striving for elegance · 18.15 Summary

What you learn in chapter 18 →

Chapter 19: An introduction to source control with Git

19.1 Why source control? · 19.2 What is Git? · 19.2.1 Installing Git · 19.2.2 Git basics · 19.3 Repository basics · 19.3.1 Creating a repository · 19.3.2 Staging a change · 19.3.3 Committing a change · 19.3.4 Rolling back a change · 19.3.5 Branching and merging · 19.4 Using Git with VS Code · 19.5 Integrating with GitHub · 19.6 Summary

What you learn in chapter 19 →

Chapter 20: Pestering your script

20.1 The vision · 20.2 Problems with manual testing · 20.3 Benefits of automated testing · 20.4 Introducing Pester · 20.5 Coding to be tested · 20.6 What do you test? · 20.6.1 Integration tests · 20.6.2 Unit tests · 20.6.3 Don’t test what isn’t yours · 20.7 Writing a basic Pester test · 20.7.1 Creating a fixture · 20.7.2 Writing the first test · 20.7.3 Creating a mock · 20.7.4 Adding more tests · 20.7.5 Code coverage · 20.8 Summary

What you learn in chapter 20 →

Chapter 21: Signing your script

21.1 The significance of script signing · 21.2 A word about certificates · 21.3 Configure your script signing policy · 21.4 Code-signing basics · 21.4.1 Acquiring a code-signing certificate · 21.4.2 Trusting self-signed certificates · 21.4.3 Signing your scripts · 21.4.4 Testing script signatures · 21.5 Summary

What you learn in chapter 21 →

Chapter 22: Publishing your script

22.1 The importance of publishing · 22.2 Exploring the PowerShell Gallery · 22.3 Other publishing options · 22.4 Before you publish · 22.4.1 Are you reinventing the wheel? · 22.4.2 Updating your manifest · 22.4.3 Getting an API key · 22.5 Ready, set, publish · 22.5.1 Managing revisions · 22.6 Publishing scripts · 22.6.1 Using the Microsoft script repository · 22.6.2 Creating ScriptFileInfo · 22.6.3 Publishing the script · 22.6.4 Managing published scripts · 22.7 Summary

What you learn in chapter 22 →

Chapter 23: Squashing bugs

23.1 The three kinds of bugs · 23.2 Dealing with syntax bugs · 23.3 Dealing with results bugs · 23.4 Dealing with logic bugs · 23.4.1 Setting breakpoints · 23.4.2 Setting watches · 23.4.3 So much more · 23.4.4 Don’t be lazy · 23.5 Your turn · 23.5.1 Start here · 23.5.2 Your task · 23.5.3 Our take · 23.6 Summary

What you learn in chapter 23 →

Chapter 24: Enhancing script output presentation

24.1 Our starting point · 24.2 Creating a default view · 24.2.1 Exploring Microsoft’s views · 24.2.2 Adding a custom type name to output objects · 24.2.3 Creating a new view file · 24.2.4 Adding the view file to a module · 24.3 Your turn · 24.3.1 Start here · 24.3.2 Your task · 24.3.3 Our take · 24.4 Summary

What you learn in chapter 24 →

Chapter 25: Wrapping up the .NET Framework

25.1 Why PowerShell exists · 25.1.1 A crash course in .Net · 25.2 Exploring a class · 25.3 Making a wrapper · 25.4 A more practical example · 25.5 Your turn · 25.5.1 Start here · 25.5.2 Your task · 25.5.3 Our take · 25.6 Summary

What you learn in chapter 25 →

Chapter 26: Storing data—not in Excel!

26.1 Introducing SQL Server! · 26.2 Setting up everything · 26.3 Using your database: Creating a table · 26.4 Saving data to SQL Server · 26.5 Querying data from SQL Server · 26.6 Summary

What you learn in chapter 26 →

Chapter 27: Never the end

27.1 Welcome to toolmaking · 27.2 Taking your next step · 27.3 What’s in your future? · 27.4 Summary

What you learn in chapter 27 →

Concepts explained in this book

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.