我怎么能知道省略PowerShell的功能参数 [英] How can I know that PowerShell function parameter is omitted

查看:224
本文介绍了我怎么能知道省略PowerShell的功能参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑这样的功能:

function Test($foo, $bar)
{
  ...
}

我们可以把它叫做:

Test -foo $null
Test

我怎么能知道什么时候被省略了-foo,当它是$空?

How can I know when the -foo was omitted, and when it was $null?

推荐答案

如果你正在使用PowerShell的V2,您可以使用$ PSBoundParameters变量,它是在目前的范围内列出了所有绑定参数的字典。

If you are using Powershell V2, you can use the $PSBoundParameters variable which is a dictionary that lists all bound parameters at current scope.

请参阅博客文章,讨论它。

See this blog post that discusses it.

这篇关于我怎么能知道省略PowerShell的功能参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆