From the course: Complete Guide to PowerShell 7

Unlock this course with a free trial

Join today to access over 24,400 courses taught by industry experts.

Advanced parameter handling

Advanced parameter handling

- [Instructor] Now, of course in the previous example, we just looked at simple parameters, you know, adding something in, using an alias, et cetera. But there's much more available to us with parameters. So in our first example here, we're going to say get user info, and then we have a parameter called username, and then we have this parameter object that's inside the param container that says mandatory equals true. So what does that look like? Well, let's just run it here and I'm going to say get user info and run that and then notice what it does. It stops me executing because it's like, wait, you need to supply a value. So I'm going to say Alice, and then of course it'll say fetching data for Alice. Now if I happen to pass that in the command line, then I don't get that message. It just says, fetching data for Alice. So the required option, so this one here that says mandatory equals true forces the person executing the function to actually have to pass a value of some…

Contents