強制引數

函式的引數可以標記為必需引數

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

如果在沒有值的情況下呼叫該函式,命令列將提示輸入值:

$greeting = Get-Greeting 

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