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

1 year ago.

  • Author
  • #100051

    Topics: 9
    Replies: 45
    Points: 17
    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:


    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[]}}


    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

    Topics: 13
    Replies: 4872
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    That's how it's designed to work.

    • #100054

      Topics: 9
      Replies: 45
      Points: 17
      Rank: Member

      Ok, thanks.

  • #100057

    Topics: 2
    Replies: 428
    Points: 835
    Helping Hand
    Rank: Major Contributor

    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.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort