且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检查函数中是否存在参数

更新时间:2023-02-23 18:59:10

使用 $PSBoundParameters.ContainsKey() 来检查参数是否存在:

Use $PSBoundParameters.ContainsKey() in order to check for a parameter presence:

function T
{
    Param
    (
        [switch] $IsValueNameRegularExpression
    )

    $PSBoundParameters.ContainsKey('IsValueNameRegularExpression')
}

T
T -IsValueNameRegularExpression
T -IsValueNameRegularExpression:$false

输出:

False
True
True