Introduction
Functions let you group commands together to reuse them easily. They help keep your scripts neat and save time.
function FunctionName { # commands go here }
function SayHello { Write-Output "Hello, world!" }
function Add-Numbers { param($a, $b) return ($a + $b) }
function Greet { param($name) Write-Output "Hello, $name!" } Greet -name "Alice"
Greet in PowerShell?function Add-Numbers {
param($a, $b)
return $a + $b
}
Add-Numbers 3 5function SayHello {
param($name)
Write-Output "Hello, $name"
}Get-Square that takes a number and returns its square. Which function definition correctly achieves this?Pass the test and this pattern moves unknown