[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

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

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

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

    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
    1. Advertisements

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

    PS C:\Documents and Settings\mehmetd>
    PS C:\Documents and Settings\mehmetd>
    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]
    Cmdlet Add-History Add-History [[-InputObject]
    Cmdlet Add-Member Add-Member [-MemberType]
    Cmdlet Add-PSSnapin Add-PSSnapin [-Name]
    Function B: Set-Location B:
    Function C: Set-Location C:
    Cmdlet Clear-Content Clear-Content [-Path]
    Function Clear-Host $spaceType =
    Cmdlet Clear-Item Clear-Item [-Path]
    Cmdlet Clear-ItemProperty Clear-ItemProperty [-Path]
    Cmdlet Clear-Variable Clear-Variable [-Name]
    Cmdlet Compare-Object Compare-Object
    Mehmet Demir [MSFT], May 1, 2006
    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.