This article describes that when you customize the PowerShell function, you can use @psboundparameters to pass arguments to another function.
Next, we'll create a get-bios function,
Copy Code code as follows:
function Get-bios
{
Param
(
$ComputerName,
$Path
)
Get-wmiobject-class Win32_BIOS @PSBoundParameters
}
In this function, we do not do any actual operations, but the input parameters are packaged and passed to the Get-wmiobject function. Attention
before we output the value of the psboundparameters variable, we add a dollar sign ($), or $psboundparameters, to represent a variable in front of it. And here we pass the parameters and parameter values to another function, we add a @ symbol before the psboundparameters. That's an important difference!
In addition, we can do some processing of the received parameters before passing the parameters to another function, such as removing one of the other parameters.
Copy Code code as follows:
function Get-bios
{
Param
(
$SomethingElse,
$ComputerName,
$Path
)
$null = $PSBoundParameters. Remove (' SomethingElse ')
"The parameter $SomethingElse still exists but won't get splatted"
Get-wmiobject-class Win32_BIOS @PSBoundParameters
}
See, we removed the SomethingElse parameter from the $psboundparameters above. Thus, there is no such argument in the argument passed to the Get-wmiobject function.
About PowerShell function pass parameter to another function, this article introduces so many, hope to be helpful to you, thank you!