Creating Simple Functions
Swipe to show menu
PowerShell functions are blocks of code that you can define once and use multiple times throughout your scripts. Functions can take parameters, which allow you to pass information into them. In the example above, the param block declares a parameter named Name of type string. When you call the function and provide a value for Name, the function returns a string that includes the value you passed. A function can return a value using the return keyword, or simply output data by writing it to the pipeline.
function Get-Greeting {
param (
[string]$Name
)
return "Hello, $Name!"
}
Everything was clear?
Thanks for your feedback!
Section 2. Chapter 4
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Section 2. Chapter 4