PowerShell PowerShell Functions Mandatory Parameters


Example

Parameters to a function can be marked as mandatory

function Get-Greeting{
    param
    (
        [Parameter(Mandatory=$true)]$name
    )
    "Hello World $name"
}

If the function is invoked without a value, the command line will prompt for the value:

$greeting = Get-Greeting 

cmdlet Get-Greeting at command pipeline position 1
Supply values for the following parameters:
name: