What I understood is "Functions in PowerShell scripting are named code block which enables an easy way to organize the script commands."
& Define using:
Function [Scope Type:]<Function name>
For Example:
Function Test
{
Write-Host "Test method"
}
Test
Functions with parameters
Example:
Function Test( $msg)
{
Param ([string] $msg)
Write-Host "$msg"
}
Test "Test method"
Output:
Test method
Parameter types:
Named params:
Param ([int] $first,[int] $second)Positional Params:
$args[0], $args[1]Switch params:
Param([Switch] $one,[Switch] $two)Dynamic params:
Set-Item -path alias:OpenNotepad -value c:\windows\notepad.exe
How do these "switch parameters" work in PowerShell scripting?