O'Reilly logo

PowerShell Troubleshooting Guide by Michael Shepard

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using untyped or [object] parameters

When writing a function with flexibility in mind, we might be tempted to omit a type on a parameter in order to allow the user to supply different kinds of objects as arguments. PowerShell definitely allows for this, and in PowerShell Version 1.0 this was a common practice. With PowerShell Version 2.0, and with the introduction of advanced functions and parameter sets, we have a better option.

Recall that PowerShell doesn't allow the overloading of functions, where multiple function definitions exist with distinct signatures. If it did, some built-in cmdlets would have over a dozen different definitions. Instead, the concept of parameter sets, or mutually exclusive sets of parameters, is provided. Each parameter ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required