From the course: PowerShell: Functions for Advanced Automation

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Parameter attributes and validation

Parameter attributes and validation

From the course: PowerShell: Functions for Advanced Automation

Start my 1-month free trial

Parameter attributes and validation

- [Instructor] I've mentioned before that parameters will increase the flexibility of PowerShell functions. Once you begin creating advanced functions with custom arguments, you're also going to want to define how those parameters are used. You're going to want to make some arguments mandatory. You may want to validate what is assigned and how it's assigned as a parameter. Or you may want to specify that a parameter could come in through the pipeline. All of this is done in the beginning of a function. It's done inside the parentheses that follow Param. In the previous video, I created this function that accepted a parameter name MyNumber. Let's go ahead and put a little working space in here. I'm going to click right before the name of the parameter, and hit Enter a few times. And in this space, we're going to define how this parameter is used. We're going to add some validation and other attributes. If I wanted to make this argument mandatory, I could add that definition here, I'm…

Contents