Get-Command question

This topic contains 3 replies, has 3 voices, and was last updated by  Joel Sallow 3 weeks, 2 days ago.

  • Author
    Posts
  • #100051

    Ivan
    Participant

    I haven't noticed this before, but, when the Get-Command is typed using the -ShowCommandInfo parameter the system returns the syntax of a cmdlet, however, if you do the same using a function created by you (in a module) the system returns the source code, am I missing something? or is this by design?, I've tried adding a manifest, inline help etc and the results are the same, look at the following examples:

    Cmdlet:

    PS C:\WINDOWS\system32> Get-Command Test-Connection -ShowCommandInfo
    
    
    Name          : Test-Connection
    ModuleName    : Microsoft.PowerShell.Management
    Module        : @{Name=Microsoft.PowerShell.Management}
    CommandType   : Cmdlet
    Definition    :
                    Test-Connection [-ComputerName]  [-AsJob] [-DcomAuthentication ] [-WsmanAuthentication ] [-Protocol
                    ] [-BufferSize ] [-Count ] [-Impersonation ] [-ThrottleLimit ] [-TimeToLive ] [-Delay 
                    []
    
                    Test-Connection [-ComputerName]  [-Source]  [-AsJob] [-DcomAuthentication ] [-WsmanAuthentication
                    ] [-Protocol ] [-BufferSize ] [-Count ] [-Credential ] [-Impersonation ]
                    [-ThrottleLimit ] [-TimeToLive ] [-Delay ] []
    
                    Test-Connection [-ComputerName]  [-DcomAuthentication ] [-WsmanAuthentication ] [-Protocol ]
                    [-BufferSize ] [-Count ] [-Impersonation ] [-TimeToLive ] [-Delay ] [-Quiet] []
    
    ParameterSets : {@{Name=Default; IsDefault=True; Parameters=System.Management.Automation.PSObject[]}, @{Name=Source; IsDefault=False;
                    Parameters=System.Management.Automation.PSObject[]}, @{Name=Quiet; IsDefault=False; Parameters=System.Management.Automation.PSObject[]}}
    

    Function:

    PS C:\WINDOWS\system32> Get-Command Show-SampleCmdlet -ShowCommandInfo
    
    
    Name          : Show-SampleCmdlet
    ModuleName    : SampleToolbox
    Module        : @{Name=SampleToolbox}
    CommandType   : Function
    Definition    :
    
                             Get-Command | Where-Object {$_.Name -like "*Sample*"} | Select-Object Name
    
    
    ParameterSets : {@{Name=__AllParameterSets; IsDefault=False; Parameters=System.Management.Automation.PSObject[]}}
    

    This is Windows PowerShell 5.1

  • #100053

    Don Jones
    Keymaster

    That's how it's designed to work.

    • #100054

      Ivan
      Participant

      Ok, thanks.

  • #100057

    Joel Sallow
    Participant

    To elaborate a bit, when a command comes from a binary module (usually a compiled C# .dll), Get-Command can't get the source code. If you call it on a command that comes from a script-type module instead (which is in plain text), you will get the script source code.

You must be logged in to reply to this topic.