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()
}
[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
Key Value
— —–
name Tobias
id 12