@@ -80,23 +80,43 @@ public CommandInfo GetCommandInfo(string commandName, CommandTypes? commandTypes
80
80
/// <returns>Returns null if command does not exists</returns>
81
81
private CommandInfo GetCommandInfoInternal ( string cmdName , CommandTypes ? commandType )
82
82
{
83
+ string moduleName = null ;
84
+ string actualCmdName = cmdName ;
85
+
86
+ // Check if cmdName is in the format "moduleName\CmdletName" (exactly one backslash)
87
+ int backslashIndex = cmdName . IndexOf ( '\\ ' ) ;
88
+ if (
89
+ backslashIndex > 0 &&
90
+ backslashIndex == cmdName . LastIndexOf ( '\\ ' ) &&
91
+ backslashIndex != cmdName . Length - 1 &&
92
+ backslashIndex != 0
93
+ )
94
+ {
95
+ moduleName = cmdName . Substring ( 0 , backslashIndex ) ;
96
+ actualCmdName = cmdName . Substring ( backslashIndex + 1 ) ;
97
+ }
83
98
// 'Get-Command ?' would return % for example due to PowerShell interpreting is a single-character-wildcard search and not just the ? alias.
84
99
// For more details see https://github.com/PowerShell/PowerShell/issues/9308
85
- cmdName = WildcardPattern . Escape ( cmdName ) ;
100
+ actualCmdName = WildcardPattern . Escape ( actualCmdName ) ;
86
101
87
102
using ( var ps = System . Management . Automation . PowerShell . Create ( ) )
88
103
{
89
104
ps . RunspacePool = _runspacePool ;
90
105
91
106
ps . AddCommand ( "Get-Command" )
92
- . AddParameter ( "Name" , cmdName )
107
+ . AddParameter ( "Name" , actualCmdName )
93
108
. AddParameter ( "ErrorAction" , "SilentlyContinue" ) ;
94
109
95
110
if ( commandType != null )
96
111
{
97
112
ps . AddParameter ( "CommandType" , commandType ) ;
98
113
}
99
114
115
+ if ( ! string . IsNullOrEmpty ( moduleName ) )
116
+ {
117
+ ps . AddParameter ( "Module" , moduleName ) ;
118
+ }
119
+
100
120
return ps . Invoke < CommandInfo > ( )
101
121
. FirstOrDefault ( ) ;
102
122
}
0 commit comments