From the course: Learning PowerShell for Windows Server Administration

Unlock the full course today

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

Creating functions

Creating functions

From the course: Learning PowerShell for Windows Server Administration

Start my 1-month free trial

Creating functions

- [Instructor] Functions are important building blocks when creating PowerShell scripts. You will most likely find actions that you want to include in your scripts that take multiple commandlets to complete, or require several parameters that need to be used the same each time to produce the output that you're looking for. You might think of functions as a way to create your own custom commandlets, that you can use in your PowerShell sessions or within your scripts. Functions are a nice way to make sure you do repeating tasks the same every time. Consider for example, displaying the time of day. There is no commandlet, Get-Time. If I were to attempt to run it, I'd get an error message saying that it's not a recognized commandlet or function. There is a commandlet, Get-Date, when run with no parameters, will display both the current date and time. So, that's pulling the time. If I wanted to regularly show just the current time, I could use Get-Date and apply a parameter to format that…

Contents