Determining Function Parameters Supplied by User

by Nov 18, 2010

To find out which parameters that a user submitted to a self-defined function, you can use $PSCmdlet like this:

function Get-Parameters {
[CmdletBinding()]
param(
$name,
$surname="Default",
$age,
$id
)
$PSCmdlet.MyInvocation.BoundParameters.GetEnumerator()
}

Test it:

Get-Parameters -Name Tobias -ID 12
Key Value
—–
name Tobias
id 12

Twitter This Tip!
ReTweet this Tip!