Book Image

PowerShell Troubleshooting Guide

By : Mike Shepard
Book Image

PowerShell Troubleshooting Guide

By: Mike Shepard

Overview of this book

Table of Contents (15 chapters)
PowerShell Troubleshooting Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Reducing input set


It's often easy when debugging, or trying to understand what has happened in a script, to be overwhelmed by the sheer volume of output. One simple strategy to help troubleshoot a script is to reduce the number of objects or input being considered in the script in order to be able to focus more clearly on what is being done.

The first way I do this is to only consider a data point or set of points that I understand really well. So instead of having the script pull in all of the servers from a CSV file, I might use a smaller CSV file or use a different parameter to have it look at a specific server. For instance, consider the following script:

function generate-bigreport{
[CmdletBinding()]
Param([Parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
      [Alias('CN','MachineName')]
      [string[]]$computerName=$env:ComputerName) 
    #do lots of interesting and complicated stuff here
}

Instead of piping in all of the computers in my active directory, I...