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

Homegrown common parameters


Also in the time of PowerShell Version 1.0, the only way to get native support for common parameters (for example, –Verbose and –ErrorAction) was to write a cmdlet using managed code. Since scripters, in general, are not C# or VB.NET programmers, there was a tendency at that time to manually implement the common parameters. For instance, it wasn't uncommon to find code like this:

function Get-Stuff{
Param($stuffID,[switch]$help)

    if($help){
      write-host "Usage: get-stuff [-stuffID] ID"
      write-host "Retrieves a list of stuff which matches"
      write-host "the given stuffID"
      return
    }
    #get the stuff
}

This was not an unapproved method in fact. Here is a blog post from Jeffery Snover advocating implementing the –whatif, –Confirm, and –Verbose parameters in script:

http://blogs.msdn.com/b/powershell/archive/2007/02/25/supporting-whatif-confirm-verbose-in-scripts.aspx#10555359

The post even contains a note explaining how important this method...