Functions in PowerShell
Functions are used to encapsulate code and reuse it throughout a script or module. They are declared using the function keyword followed by the function name and parameters. Here's an example:
function Get-Greeting {
param($name)
return "Hello, $name!"
}
$greeting = Get-Greeting -name "John"
Write-Host $greeting
In this example, we define a function called Get-Greeting that takes a parameter called $name and returns a greeting message. We then call the function and store the result in the $greeting variable.
No comments:
Post a Comment