Simple Function with No Parameters

suggest change

This function writes a string to the pipeline. The assignment stores that string in a variable.

function Get-Greeting{
    "Hello World"
}

# Invoking the function
$greeting = Get-Greeting

# demonstrate output
$greeting
Get-Greeting

function declares the following code to be a function.

Get-Greeting is the name of the function. Any time that function needs to be used in the script, the function can be called by means of invoking it by name.

{ ... } is the script block that is executed by the function.

Running the two lines after the assignment prints:

Hello World
Hello World

Feedback about page:

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



Table Of Contents