Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I know that PowerShell function parameter is omitted

Consider such function:

function Test($foo, $bar)
{
  ...
}

We can call it:

Test -foo $null
Test

How can I know when the -foo was omitted, and when it was $null?

like image 490
alex2k8 Avatar asked Dec 30 '25 06:12

alex2k8


1 Answers

If you are using Powershell V2 or later, you can use the $PSBoundParameters variable which is a dictionary that lists all bound parameters at current scope.

See this blog post that discusses it.

like image 182
zdan Avatar answered Jan 01 '26 02:01

zdan