[ Web Proxy ]
URL:
Viewing: https://powershellguide.com/PowerShell/Functions [Back]  [Original]

PowerShell Guide - Functions
PowerShell Guide

Functions

Please believe me, functions are quite fun.

PowerShell functions are commands written directly in PowerShell.

Most commands you run and most commands you build will be functions.

Functions are named scriptblocks.

Anything you can do with a ScriptBlock, you can do with a Function.

Lets start simple, by declaring a Hello World function.


function HelloWorld {
    "Hello World"
}

You can declare functions parameters inline:


function Hello($Message = 'Hello World') {
    $Message
}

You can also declare parameters in a param() block


function Hello {
    param(
    $Message = 'Hello World'
    )
    $Message
}

These are all examples of simple functions.

Its not meant to be snide, its just that PowerShell functions can get much more advanced.

Advanced Functions can bind to anything in the Object Pipeline, Prompt for Confirmation, and have rich inline help.

Color Scheme :

Web Proxy Viewer  |  New URL  |  Original Page