Author Posts

May 1, 2018 at 4:11 pm

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

May 1, 2018 at 4:12 pm

That's how it's designed to work.

May 1, 2018 at 4:58 pm

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.