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

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…

Contents