Summary of the new feature / enhancement
There is currently a $PSBoundParameters automatic variable which includes any parameters/values passed to the command. But this variable doesn't include parameters which have default values. There are times when users want any assigned parameter key/values passed to another function--including any default values if the user didn't pass a value to that parameter. Basically any parameter variables which hold a value, whether that value was provided by the user or a default value.
I'd like to propose a $PSAssignedParameters automatic variable which includes any parameters with assigned values, whether they be bound parameters passed by the user, or parameters not passed by the user, but with default values.
Current functionality:
PS > function Get-BoundParameters {
param (
$Param1 = "This is param1",
$Param2,
$Param3
)
[PSCustomObject] $PSBoundParameters
}
PS > Get-BoundParameters -Param2 "This is param2"
Param2
------
This is param2
Currently, only $Param2 is returned, whereas the desired result (for the proposed $PSAssignedParameters variable) is that both $Param1 and $Param2 are returned, since both variables have assigned values--$Param1 from the default value, and $Param2 from the value passed by the user.
Proposed technical implementation details (optional)
Desired functionality:
PS > function Get-AssignedParameters {
param (
$Param1 = "This is param1",
$Param2,
$Param3
)
[PSCustomObject] $PSAssignedParameters
}
PS > Get-AssignedParameters -Param2 "This is param2"
Param1 Param2
------ ------
This is param1 This is param2
The $PSAssignedParameters automatic variable would hold any parameters which have assigned values, whether that value was assigned by the user during runtime, or it's a default value. In this example, it returns $Param1 with the default value and $Param2 with the user-provided value, but doesn't return $Param3 because it doesn't have a value at all.
Possible challenges / considerations
- How to approach switch/boolean parameters. If the switch/boolean is unused, should it be included in the
$PSAssignedParameters hash with a $false value, or should it not be included at all?
- How to handle dynamic parameters
Summary of the new feature / enhancement
There is currently a
$PSBoundParametersautomatic variable which includes any parameters/values passed to the command. But this variable doesn't include parameters which have default values. There are times when users want any assigned parameter key/values passed to another function--including any default values if the user didn't pass a value to that parameter. Basically any parameter variables which hold a value, whether that value was provided by the user or a default value.I'd like to propose a
$PSAssignedParametersautomatic variable which includes any parameters with assigned values, whether they be bound parameters passed by the user, or parameters not passed by the user, but with default values.Current functionality:
Currently, only
$Param2is returned, whereas the desired result (for the proposed$PSAssignedParametersvariable) is that both$Param1and$Param2are returned, since both variables have assigned values--$Param1from the default value, and$Param2from the value passed by the user.Proposed technical implementation details (optional)
Desired functionality:
The
$PSAssignedParametersautomatic variable would hold any parameters which have assigned values, whether that value was assigned by the user during runtime, or it's a default value. In this example, it returns$Param1with the default value and$Param2with the user-provided value, but doesn't return$Param3because it doesn't have a value at all.Possible challenges / considerations
$PSAssignedParametershash with a$falsevalue, or should it not be included at all?