From the course: Complete Guide to PowerShell 7
Unlock this course with a free trial
Join today to access over 24,800 courses taught by industry experts.
Creating simple functions - PowerShell Tutorial
From the course: Complete Guide to PowerShell 7
Creating simple functions
- [Instructor] Now, obviously one of the key things within PowerShell is creating functions. So not only executing commandlets, but also functions itself. So let's have a look at some basic functions. Well, first off, we have one here. This is called Get-Greeting, and it's going to output a value. So we right click, choose Run Selection. I'm going to slide this a bit further up here, and then we say Get-Greeting. And sure enough, it just writes the output. So the construct of a function is really the function, the name, and then what it is you want it to do as far as logic will go. So to make it a bit more complicated, instead of rendering a message, let's utilize what's called param. So param allows me to add specific things together or add properties or add requirements, I suppose, to a function. So this one's called Add-Numbers and it's going to require a parameter of $a and $b, and then we're simply going to add those together. So I'm going to say Run Selection, and then if I say…
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)
-
-
-
-
-
-
-