powershell - 获取非 "common parameters"的绑定(bind)参数?

标签 powershell

简单的例子

function Verb-Noun
{
    [CmdletBinding()]
    Param
    (
        [Parameter(Mandatory=$true,
                   ValueFromPipelineByPropertyName=$true,
                   Position=0)]
        $Param1,

        [int]
        $Param2
    )

    Begin
    {
    }
    Process
    {
        $PSBoundParameters
    }
    End
    {
    }
}

Verb-Noun 'some param value' -Verbose

ofc返回

Key     Value           
---     -----           
Verbose True            
Param1  some param value

那么,如何获取所有绑定(bind)参数但不获取[CmdletBinding()]提供的常用参数? ...在 abobe 中没有详细说明

最佳答案

没有特定的内置方法可以做到这一点,但您可以从哈希表中删除通用参数。要以编程方式列出常用参数,请参阅 this question .

我正在使用PowerShell 2 answer from that question ,所以我们可以这样做:

Function Get-egCommonParameterNames
{
    [CmdletBinding()]
    param()
    process
    {
        (Get-Command Get-egCommonParameterNames).Parameters.Keys
    }
}

$myParams = [hashtable]$PSBoundParameters
Get-egCommonParameterNames | ForEach-Object { $myParams.Remove($_) }

Do note that each step of a pipeline could have different bound parameters .

关于powershell - 获取非 "common parameters"的绑定(bind)参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34294518/

相关文章:

powershell - 在一个巨大的文本文件中获取所有包含字符串的行-尽快?

powershell - 我需要我的脚本在 -Whatif 输出中包含 "LastWriteTime"属性

powershell - 为什么从函数调用时 PowerShell 代码的行为有所不同?

powershell - 尝试使用 PowerShell 脚本从 Active Directory 中的所有组中删除用户

sql-server - 将多个 dacpac 文件部署到单个数据库

powershell - PNP powershell SharePoint Online 设置新式页面横幅imageurl

powershell - 在Powershell中拆分WMI对象

powershell - 如何在PowerShell中替换以零,一个或多个空格开头的字符串

c# - 通过 C# 中的属性检索嵌套 Powershell 对象的值

powershell - 如何使用Powershell关闭现有IE窗口中的选项卡