[PS] Should Get-Command's -CommandType <CommandTypes> be a list item?

Discussion in 'Scripting' started by Alex K. Angelopoulos [MVP], May 1, 2006.

  1. From pluralization it seems clear that the intent is for
    Get-Command -CommandType to accept multiple types of commands. That would be
    useful as well. However, it doesn't work:

    PS> Get-Command -CommandType ExternalScript,Function
    Get-Command : Cannot convert 'System.Object[]' to the type
    'System.Management.Automation.CommandTypes' required by parameter
    'CommandType'. Specified method is not supported.
    At line:1 char:25
    + Get-Command -CommandType <<<< ExternalScript,Function
    PS>

    Bug this?
     
    Alex K. Angelopoulos [MVP], May 1, 2006
    #1
    1. Advertisements

  2. S.M.A.CommandTypes is a [Flags] type enum.

    When you use the following you are passing multiple values to -CommandType
    parameter:

    Get-Command -CommandType ExternalScript,Function

    Use the following to pass a single value with the ExternalScript and
    Function bits combined:

    Get-Command -CommandType 'ExternalScript,Function'

    (It might sometimes be a nice feature if MSH just ORed array of enum values
    to a single value...)
     
    Jouko Kynsijärvi, May 1, 2006
    #2
    1. Advertisements

  3. Yes it might mislead, it is actually an enum

    PS C:\Documents and Settings\mehmetd>
    $a=[System.Management.Automation.CommandTy
    pes]::Function
    PS C:\Documents and Settings\mehmetd>
    $b=[System.Management.Automation.CommandTy
    pes]::Cmdlet
    PS C:\Documents and Settings\mehmetd> $c= $a -bor $b
    PS C:\Documents and Settings\mehmetd> get-command -CommandType $c

    CommandType Name Definition
    ----------- ---- ----------
    Function A: Set-Location A:
    Cmdlet Add-Content Add-Content [-Path]
    <String[...
    Cmdlet Add-History Add-History [[-InputObject]
    ....
    Cmdlet Add-Member Add-Member [-MemberType]
    <PS...
    Cmdlet Add-PSSnapin Add-PSSnapin [-Name]
    <String...
    Function B: Set-Location B:
    Function C: Set-Location C:
    Cmdlet Clear-Content Clear-Content [-Path]
    <Strin...
    Function Clear-Host $spaceType =
    [System.Managem...
    Cmdlet Clear-Item Clear-Item [-Path]
    <String[]...
    Cmdlet Clear-ItemProperty Clear-ItemProperty [-Path]
    <...
    Cmdlet Clear-Variable Clear-Variable [-Name]
    <Stri...
    Cmdlet Compare-Object Compare-Object
    [-ReferenceOb...
     
    Mehmet Demir [MSFT], May 1, 2006
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.