Create a function with optional call variables

后端 未结 3 379
南笙
南笙 2021-01-01 11:39

Is there a way to create a parameter in a PowerShell function where you have to call it in order to have it considered?

An example given by commandlet (the bold bein

3条回答
  •  情深已故
    2021-01-01 11:50

    Powershell provides a lot of built-in support for common parameter scenarios, including mandatory parameters, optional parameters, "switch" (aka flag) parameters, and "parameter sets."

    By default, all parameters are optional. The most basic approach is to simply check each one for $null, then implement whatever logic you want from there. This is basically what you have already shown in your sample code.

    If you want to learn about all of the special support that Powershell can give you, check out these links:

    about_Functions

    about_Functions_Advanced

    about_Functions_Advanced_Parameters

提交回复
热议问题