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 - PowerShell Tutorial
From the course: Complete Guide to PowerShell 7
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
(Locked)
Introduction to functions6m 4s
-
(Locked)
Creating simple functions3m 20s
-
(Locked)
Using parameters in functions6m 28s
-
(Locked)
Advanced parameter handling6m 16s
-
(Locked)
Validating parameters5m 57s
-
(Locked)
Returning values from functions2m 34s
-
(Locked)
Creating reusable functions8m 33s
-
(Locked)
Function libraries and modules4m 30s
-
(Locked)
-
-
-
-
-
-
-