Function

suggest change

A function is a named block of code which is used to define reusable code that should be easy to use. It is usually included inside a script to help reuse code (to avoid duplicate code) or distributed as part of a module to make it useful for others in multiple scripts.

Scenarios where a function might be useful:

Functions are created using the function keyword, followed by a single-word name and a script block containing the code to executed when the function name is called.

function NameOfFunction {
    Your code
}

Demo

function HelloWorld {
    Write-Host "Greetings from PowerShell!"
}

Usage:

> HelloWorld
Greetings from PowerShell!

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Modules scripts and functions:
* Function
* Script
* Module

Table Of Contents
1 Loops
19 XML
22 Strings
25 Aliases
37 Modules scripts and functions
47 MongoDB
65 AWS S3