Windows PowerShell Scripting & Toolmaking

Introduction

This  five-day instructor-led is intended for IT professionals who are interested in furthering their skills in Windows PowerShell and administrative automation. The course assumes a basic working knowledge of PowerShell as an interactive command-line shell, and teaches students the correct patterns and practices for building reusable, tightly scoped units of automation.

Audience

This course is intended for administrators that have little or no programming experience, but who have a working knowledge of Windows PowerShell and who are able to use Windows PowerShell to run complex, interactive commands.

Prerequisites

Before attending this course, participants should have:
 
  • Experience in administering Windows server and client computers
  • Experience in running interactive Windows PowerShell commands from the command prompt
  • Course 10961 is strongly recommended as a pre-requisite to this course

At course completion

At the end of this course, participants will be able to:

  • Design tools, including input requirements, output requirements, and functional requirements.
  • Write tools, including scripting, parameterizing commands, and providing verbose output
  • Debug tools and provide error handling within tools
  • Combine tools into script and manifest modules
  • Create custom formatting views
  • Create tools that are consistent in naming and operation with native Windows PowerShell tools

Exams

N/A

Course outline

Module 1: Tool Design

This module explains how to design tools and units of automation that comply with native PowerShell usage patterns.

  • Lesson 1: Tools do one thing
  • Lesson 2: Tools are flexible
  • Lesson 3: Tools look native

Module 2: Start with a Command

This module explains how to start the scripting process by beginning in the interactive shell console.

  • Lesson 1: Why start with a command?
  • Lesson 2: Discovery and experimentation

Module 3: Build a Basic Function and Module

This module explains how to build a basic function and module, using commands already experimented with in the shell.

  • Lesson 1: Start with a basic function
  • Lesson 2: Create a script module
  • Lesson 3: Check prerequisites
  • Lesson 4: Run the new command

Module 4: Adding CmdletBinding and Parameterizing

This module explains how to extend the functionality of a tool, parameterize input values, and use CmdletBinding.

  • Lesson 1: About CmdletBinding and common parameters
  • Lesson 2: Accepting pipeline input
  • Lesson 3: Mandatory-ness
  • Lesson 4: Parameter validation
  • Lesson 5: Parmeter aliases

Module 5: Emitting Objects as Output

This module explains how to create tools that produce custom objects as output.

  • Lesson 1: Assembling information
  • Lesson 2: Constructing and emitting output
  • Lesson 3: Quick tests

Module 6: An Interlude: Changing Your Approach

This module explains how to re-think tool design, using concrete examples of how it’s often done wrong.

  • Lesson 1: Examining a script
  • Lesson 2: Critiquing a script
  • Lesson 3: Revising the script

Module 7: Using Verbose, Warning, and Informational Output

This module explains how to use additional output pipelines for better script behaviors.

  • Lesson 1: Knowing the six channels
  • Lesson 2: Adding verbose and warning output
  • Lesson 3: Doing more with verbose output
  • Lesson 4: Informational output

Module 8: Comment-Based Help

This module explains how to add comment-based help to tools.

  • Lesson 1: Where to put your help
  • Lesson 2: Getting started
  • Lesson 3: Going further with comment-based help
  • Lesson 4: Broken help

Module 9: Handling Errors

This module explains how to create tools that deal with anticipated errors.

  • Lesson 1: Understanding errors and exceptions
  • Lesson 2: Bad handling
  • Lesson 3: Two reasons for exception handling
  • Lesson 4: Handling exceptions in our tool
  • Lesson 5: Capturing the actual exception
  • Lesson 6: Handling exceptions for non-commands
  • Lesson 7: Going further with exception handling
  • Lesson 8: Deprecated exception handling

Module 10: Basic Debugging

This module explains how to use native PowerShell script debugging tools.

  • Lesson 1: Two kinds of bugs
  • Lesson 2: The ultimate goal of debugging
  • Lesson 3: Developing assumptions
  • Lesson 4: Write-Debug
  • Lesson 5: Set-PSBreakpoint
  • Lesson 6: The PowerShell ISE

Module 11: Going Deeper with Parameters

This module explains how to further define parameter attributes in a PowerShell command.

  • Lesson 1: Parameter positions
  • Lesson 2: Validation
  • Lesson 3: Multiple parameter sets
  • Lesson 4: Value from remaining arguments
  • Lesson 5: Help messages
  • Lesson 6: Aliases
  • Lesson 7: More CmdletBinding

Module 12: Writing Full Help

This module explains how to create external help for a command.

  • Lesson 1: External help
  • Lesson 2: Using PlatyPs
  • Lesson 3: Supporting online help
  • Lesson 4: “About” topics
  • Lesson 5: Making your help updatable

Module 13: Unit Testing Your Code

This module explains how to use Pester to perform basic unit testing.

  • Lesson 1: Sketching out the test
  • Lesson 2: Making something to test
  • Lesson 3: Expanding the test
  • Lesson 4: Going further with Pester

Module 14: Extending Output Types

This module explains how to extend objects with additional capabilities.

  • Lesson 1: Understanding types
  • Lesson 2: The Extensible Type System
  • Lesson 3: Extending an object
  • Lesson 4: Using Update-TypeData

Module 15: Analyzing Your Script

This module explains how to use Script Analyzer to support best practices and prevent common problems.

  • Lesson 1: Performing a basic analysis
  • Lesson 2: Analyzing the analysis

Module 16: Publishing Your Tools

This module explains how to publish tools to public and private repositories.

  • Lesson 1: Begin with a manifest
  • Lesson 2: Publishing to PowerShell Gallery
  • Lesson 3: Publishing to private repositories

Module 17: Basic Controllers: Automation Scripts and Menus

This module explains how to create controller scripts that put tools to use.

  • Lesson 1: Building a menu
  • Lesson 2: Using UIChoice
  • Lesson 3: Writing a process controller

Module 18: Proxy Functions

This module explains how to create and use proxy functions.

  • Lesson 1: A proxy example
  • Lesson 2: Creating the proxy base
  • Lesson 3: Modifying the proxy
  • Lesson 4: Adding or removing parameters

Module 19: Working with XML Data

This module explains how to work with XML data in PowerShell.

  • Lesson 1: Simple: CliXML
  • Lesson 2: Importing native XML
  • Lesson 3: ConvertTo-XML
  • Lesson 4: Creating native XML from scratch

Module 20: Working with JSON Data

This module explains how to using JSON data in PowerShell.

  • Lesson 1: Converting to JSON
  • Lesson 2: Converting from JSON

Module 21: Working with SQL Server Data

This module explains how to use SQL Server from within a PowerShell script.

  • Lesson 1: SQL Server terminology and facts
  • Lesson 2: Connecting to the server and database
  • Lesson 3: Writing a query
  • Lesson 4: Running a query
  • Lesson 5: Invoke-SqlCmd
  • Lesson 6: Thinking about tool design patterns