您如何以编程方式获取所有常用参数的列表

您如何以编程方式获取所有常用参数的列表

本文介绍了您如何以编程方式获取所有常用参数的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

Powershell Cmdlet继承了一堆常用参数.我写的某些cmdlet最终取决于依赖于实际绑定哪些参数的谓词.这通常会导致过滤出通用参数,这意味着您需要一个通用参数名称列表.

Powershell Cmdlets inherit a bunch of common parameters. Some cmdlets I write end up with predicates that depend on which parameters are actually bound. This often leads to filtering out common parameters which means you need a list of common parameter names.

我还希望从一个版本的Powershell到另一个版本的通用参数列表中会有差异.

I also expect there to be difference in the list of common parameters from one version of powershell to another.

所有这些都归结为以下问题:

All of this boils down to this question:

您如何以编程方式确定常用参数列表?

How do you programmatically determine the list of common parameters?

推荐答案

这些静态属性如何?

[System.Management.Automation.PSCmdlet]::CommonParameters
[System.Management.Automation.PSCmdlet]::OptionalCommonParameters

现有的通用参数是两个列表的组合:

The existing common parameters is the combination of both lists:

OptionalCommonParameters :列出在cmdlet定义其他功能(SupportsShouldProcess,SupportsTransactions)时由PowerShell引擎添加的公用参数

OptionalCommonParameters: Lists the common parameters that are added by the PowerShell engine when a cmdlet defines additional capabilities (SupportsShouldProcess, SupportsTransactions)

即它们都可以存在,但仅当cmdlet支持它们时,可选的存在.有关详细信息,请参见 Cmdlet类别

i.e. All of them can exist, but the optional ones only exists if the cmdlet supports them. For detailed info see Cmdlet Class

这篇关于您如何以编程方式获取所有常用参数的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 18:17