【问题标题】:How many parameter sets does get-childitem have?get-childitem 有多少个参数集?
【发布时间】:2014-11-04 21:05:10
【问题描述】:

看着get-help get-childitem,我数了3

语法 Get-ChildItem [[-Path] ] [[-Filter] ] [-Exclude ] [-Force] [-Include ] [-Name] [-Recurse] [-UseTransaction []] []
Get-ChildItem [[-Filter] ] [-Exclude ] [-Force] [-Include ] [-Name] [-Recurse] -LiteralPath [-UseTransaction []] []
Get-ChildItem [-Attributes] [-Directory] ​​[-File] [-Force] [-Hidden] [-ReadOnly] [-System] [-UseTransaction] []

但是,以下命令只能找到 2(Items 和 LiteralItems):

get-command get-childitem | select-object -expand ParameterSets | select-object Name

FWIW,show-command 也仅通过 UI 中的 2 个选项卡显示 2 个参数集。

我想问题是为什么生成的 get-childitem 帮助似乎打破了最后一个用例。

【问题讨论】:

    标签: powershell


    【解决方案1】:

    只有两个参数集。

    PS> gcm Get-ChildItem -syntax
    
    Get-ChildItem [[-Path] <string[]>] [[-Filter] <string>] [-Include <string[]>] [-Exclude <string[]>] [-Recurse]
    [-Force] [-Name] [-UseTransaction] [-Attributes <FlagsExpression[FileAttributes]>] [-Directory] [-File] [-Hidden]
    [-ReadOnly] [-System] [<CommonParameters>]
    
    Get-ChildItem [[-Filter] <string>] -LiteralPath <string[]> [-Include <string[]>] [-Exclude <string[]>] [-Recurse]
    [-Force] [-Name] [-UseTransaction] [-Attributes <FlagsExpression[FileAttributes]>] [-Directory] [-File] [-Hidden]
    [-ReadOnly] [-System] [<CommonParameters>]
    

    我相信帮助中显示的第三组是向您显示文件系统提供程序的动态参数。这与我在 Get-ChildItem 上执行帮助以查看证书提供者的动态参数时看到的内容相吻合,例如:

    PS> Get-Help Get-ChildItem -Full -Path cert:\
    
    SYNTAX
        Get-ChildItem [[-Path] <String[]>] [[-Filter] <String>] [-Exclude <String[]>] [-Force] [-Include <String[]>]
        [-Name] [-Recurse] [-UseTransaction [<SwitchParameter>]] [<CommonParameters>]
    
        Get-ChildItem [[-Filter] <String>] [-Exclude <String[]>] [-Force] [-Include <String[]>] [-Name] [-Recurse]
        -LiteralPath <String[]> [-UseTransaction [<SwitchParameter>]] [<CommonParameters>]
    
        Get-ChildItem [-CodeSigningCert] [-DnsName <string>] [-EKU <string>] [-ExpiringInDays <int>]
        [-SSLServerAuthentication] [<CommonParameters>]
    

    【讨论】:

    • 谢谢你,基思。我没有想到动态参数。这很有道理。
    猜你喜欢
    • 1970-01-01
    • 2013-06-06
    • 1970-01-01
    • 2017-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-17
    相关资源
    最近更新 更多