This article describes that when customizing the PowerShell function, there is a $psboundparameters variable to get to the input parameter list. Getting the input parameter list is a great help for our functional debugging.
When we execute a function, we can use the value of the input parameters, but I am in the PowerShell, the parameters are optional, some optional, then how do we know the user's actual input parameters?
In the PowerShell function, there is a global variable $psboundparameters, which is a hash table that holds all the input parameters and the values of the input parameters. By outputting This variable, we can see all the input parameters.
Copy Code code as follows:
function Get-parameter {
Param
(
$Name,
$LastName = ' Default ',
$Age,
$Id
)
$PSBoundParameters
}
This function defines four parameters, and the user can optionally select parameters for input, so we use the $psboundparameters variable to get the input parameter list.
The status of implementation is as follows:
Copy Code code as follows:
Ps> Get-parameter
Ps> Get-parameter-name Test-id 12
Key Value
--- -----
Name Test
Id 12
As you can see, the same call to this function, no input parameters, the output is empty. Parameter names and parameter values are output as they were when the parameters were entered.
About PowerShell function get input parameter list ($PSBoundParameters), this article introduces so much, hope to help you, thank you!