@@ -48,29 +48,38 @@ public async Task<List<PSCommandMessage>> Handle(GetCommandParams request, Cance
48
48
PSCommand psCommand = new PSCommand ( ) ;
49
49
50
50
// Executes the following:
51
- // Get-Command -CommandType Function,Cmdlet,ExternalScript | Select-Object -Property Name,ModuleName | Sort-Object -Property Name
51
+ // Get-Command -CommandType Function,Cmdlet,ExternalScript | Sort-Object -Property Name
52
52
psCommand
53
53
. AddCommand ( "Microsoft.PowerShell.Core\\ Get-Command" )
54
54
. AddParameter ( "CommandType" , new [ ] { "Function" , "Cmdlet" , "ExternalScript" } )
55
- . AddCommand ( "Microsoft.PowerShell.Utility\\ Select-Object" )
56
- . AddParameter ( "Property" , new [ ] { "Name" , "ModuleName" } )
57
55
. AddCommand ( "Microsoft.PowerShell.Utility\\ Sort-Object" )
58
56
. AddParameter ( "Property" , "Name" ) ;
59
57
60
- IEnumerable < PSObject > result = await _powerShellContextService . ExecuteCommandAsync < PSObject > ( psCommand ) . ConfigureAwait ( false ) ;
58
+ IEnumerable < CommandInfo > result = await _powerShellContextService . ExecuteCommandAsync < CommandInfo > ( psCommand ) . ConfigureAwait ( false ) ;
61
59
62
60
var commandList = new List < PSCommandMessage > ( ) ;
63
61
if ( result != null )
64
62
{
65
- foreach ( dynamic command in result )
63
+ foreach ( CommandInfo command in result )
66
64
{
65
+ // Get the default ParameterSet
66
+ string defaultParameterSet = null ;
67
+ foreach ( CommandParameterSetInfo parameterSetInfo in command . ParameterSets )
68
+ {
69
+ if ( parameterSetInfo . IsDefault )
70
+ {
71
+ defaultParameterSet = parameterSetInfo . Name ;
72
+ break ;
73
+ }
74
+ }
75
+
67
76
commandList . Add ( new PSCommandMessage
68
77
{
69
78
Name = command . Name ,
70
79
ModuleName = command . ModuleName ,
71
80
Parameters = command . Parameters ,
72
81
ParameterSets = command . ParameterSets ,
73
- DefaultParameterSet = command . DefaultParameterSet
82
+ DefaultParameterSet = defaultParameterSet
74
83
} ) ;
75
84
}
76
85
}
0 commit comments