Windows PowerShell Scripting and Toolmaking - M55039 Course Outline

(5 Days)

Overview

This three- to 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 Profile

This course is intended for administrators in a Microsoft-centric environment who want to build reusable units of automation, automate business processes, and enable less-technical colleagues to accomplish administrative tasks

Prerequisites

  • Experience at basic Windows administration
  • Experience using Windows PowerShell to query and modify system information
  • Experience using Windows PowerShell to discover commands and their usage
  • Experience using WMI and/or CIM to query system information

At Course Completion

  • Describe the correct patterns for building modularized tools in Windows PowerShell
  • Build highly modularized functions that comply with native PowerShell patterns
  • Build controller scripts that expose user interfaces and automate business processes
  • Manage data in a variety of formats
  • Write automated tests for tools
  • Debug tools

Course Outline

Module 1: Tool Design

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

Lessons

  • Tools do one thing
  • Tools are flexible
  • Tools look native

Lab 1: Designing a Tool

  • Design a tool

After completing this module, students will be able to:

  • Describe the native shell patterns that a good tool design should exhibit

Module 2: Start with a Command

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

Lessons

  • Why start with a command?
  • Discovery and experimentation

Lab 1: Designing a Tool

  • Start with a command

After completing this module, students will be able to:

  • Describe the benefits of discovery and experimentation in the console
  • Discover and experiment with existing commands in the console

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.

Lessons

  • Start with a basic function
  • Create a script module
  • Check prerequisites
  • Run the new command

Lab 1: Designing a Tool

  • Build a basic function and module

After completing this module, students will be able to:

  • Build a basic function
  • Create a script module
  • Run a command from a script module

Module 4: Adding CmdletBinding and Parameterizing

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

Lessons

  • About CmdletBinding and common parameters
  • Accepting pipeline input
  • Mandatory-ness
  • Parameter validation
  • Parmeter aliases

Lab 1: Designing a Tool

  • Adding CmdletBinding and Parameterizing

After completing this module, students will be able to:

  • Describe the purpose of CmdletBinding and list common parameters
  • Parameterize a script’s input
  • Define parameters as mandatory
  • Define parameters as accepting pipeline input
  • Define parameter validation

Module 5: Emitting Objects as Output

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

Lessons

  • Assembling information
  • Constructing and emitting output
  • Quick tests

Lab 1: Designing a Tool

  • Emitting objects as output

After completing this module, students will be able to:

  • Describe the purpose of object-based output
  • Create and output custom objects from a function

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.

Lessons

  • Examining a script
  • Critiquing a script
  • Revising the script

After completing this module, students will be able to:

  • Describe the native patterns that a good tool design should exhibit
  • Redesign a script to meet business requirements and conform to native patterns

Module 7: Using Verbose, Warning, and Informational Output

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

Lessons

  • Knowing the six channels
  • Adding verbose and warning output
  • Doing more with verbose output
  • Informational output

Lab 1: Designing a Tool

  • Using Verbose, Warning, and Informational Output

After completing this module, students will be able to:

  • Describe the six output channels in the shell
  • Write commands that use verbose, warning, and informational output
  • Run commands with extra output enabled

Module 8: Comment-Based Help

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

Lessons

  • Where to put your help
  • Getting started
  • Going further with comment-based help
  • Broken help

Lab 1: Designing a Tool

  • Comment-based help

After completing this module, students will be able to:

  • Describe the purpose and construction of comment-based help
  • Add comment-based help to a function
  • Identify causes of broken comment-based help

Module 9: Handling Errors

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

Lessons

  • Understanding errors and exceptions
  • Bad handling
  • Two reasons for exception handling
  • Handling exceptions in our tool
  • Capturing the actual exception
  • Handling exceptions for non-commands
  • Going further with exception handling
  • Deprecated exception handling

Lab 1: Designing a Tool

  • Handling errors

After completing this module, students will be able to:

  • Describe the native patterns for handling errors in a command
  • Add error handling to a command
  • Run a command and observe error handling behaviors

Module 10: Basic Debugging

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

Lessons

  • Two kinds of bugs
  • The ultimate goal of debugging
  • Developing assumptions
  • Write-Debug
  • Set-PSBreakpoint
  • The PowerShell ISE

Lab 1: Designing a Tool

  • Basic debugging

After completing this module, students will be able to:

  • Describe the tools used for debugging in PowerShell
  • Debug a broken script

Module 11: Going Deeper with Parameters

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

Lessons

  • Parameter positions
  • Validation
  • Multiple parameter sets