Mandatory parameters are special because if you do not submit it, PowerShell will automatically ask for it. You can use mandatory parameters in your own functions as well. You should simply mark a function as mandatory by adding the appropriate [Parameter()] attribute like so:
function Test-Me {
param(
[Parameter(Mandatory=$true)]
$name
)
"You entered $name."
}
param(
[Parameter(Mandatory=$true)]
$name
)
"You entered $name."
}
Test-Me
The parameter attributes used in this tip were introduced with PowerShell v2.