Setter function


I am building an API wrapper, with 3 simple functions “Get-MyObject”, “New-MyObject” and “Set-MyObject”.

Set-MyObject issues a PUT request to update the object, with approx. 20 fields available to be updated, each represented by an optional parameter. Is there a built-in way to inspect the parameters that the user has supplied, rather than checking each parameter in turn, i.e. I don’t want 20 instances of

if($property1){do something}

In the psuedo-code below, I’m looking for “$supplied_params”:

foreach($param in $supplied_params)

Many thanks in advance.

You can use $PSBoundParameters, it is an automatic variable which gets populated inside a script/function.

an example below.

function test {

#below executions
test 1
tert 1 2

Perfect, exactly what I was looking for.


You could probably do a nice, concise switch ($PSBoundParameters.Keys) {} and just work from there. :slight_smile: