Get-Command question

Welcome Forums General PowerShell Q&A Get-Command question

This topic contains 3 replies, has 3 voices, and was last updated by

 
Participant
6 months, 2 weeks ago.

  • Author
    Posts
  • #100051

    Participant
    Points: 1
    Rank: Member

    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

    Keymaster
    Points: 1,624
    Helping HandTeam Member
    Rank: Community Hero

    That's how it's designed to work.

    • #100054

      Participant
      Points: 1
      Rank: Member

      Ok, thanks.

  • #100057

    Participant
    Points: 160
    Helping Hand
    Rank: 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.

The topic ‘Get-Command question’ is closed to new replies.