An example of a function argument passed into another function in the PowerShell function _powershell

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.