Executive Summary:
Like any scripting language, Windows PowerShell lets you create functions. You can make functions as simple or as complex as necessary. In this lesson, you'll learn how to create your own functions, including how to incorporate named parameters and how to give those parameters default values. You'll also learn how to work with your functions' output so you can use it in PowerShell scripts.

Like any scripting language, Windows PowerShell lets you create functions that you can reference within PowerShell statements. A function is basically a named block of code. When you call the function name, the script block within that function runs. You can include any PowerShell statements within the script block, and you can add input parameters so you can use the same function in different situations. Let's look at how to create functions, define input parameters, and work with functions in PowerShell scripts.

Creating a Function

At the most basic level, a function definition (i.e., the code that defines the function) requires the function keyword, the function's name, and a script block, as the following syntax shows:

function \{

Sponsored Introduction Continue on to (or wait seconds) ×