Simple Function with No Parameters
suggest changeThis 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
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents