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

Missing Param() statements


Parameters to functions in PowerShell can be defined in two ways: either as a list following the name of the function or in a Param() statement. In Version 1.0 of PowerShell, there was no compelling reason to use a Param() statement in a function, although Param() statements were required to define parameters to scripts and scriptblocks. Since most programming languages use a parameter list following the function name, it was natural at that time to skip the use of Param() statements in functions. With the introduction of advanced functions in PowerShell Version 2.0, there was suddenly a reason to use a Param() statement, as the CmdletBinding() attribute binds to the Param() statement. That is, in order to include the CmdletBinding() attribute, you needed to include a Param() statement.

It is not necessary that all functions be advanced functions, but the effort required to make the change is trivial compared to the advantages. Common parameters, parameter checking...