5
5
using System . Collections . Concurrent ;
6
6
using System . Management . Automation ;
7
7
using System . Linq ;
8
+ using System . Management . Automation . Runspaces ;
8
9
9
10
namespace Microsoft . Windows . PowerShell . ScriptAnalyzer
10
11
{
@@ -14,16 +15,17 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer
14
15
internal class CommandInfoCache
15
16
{
16
17
private readonly ConcurrentDictionary < CommandLookupKey , Lazy < CommandInfo > > _commandInfoCache ;
17
-
18
18
private readonly Helper _helperInstance ;
19
+ private readonly RunspacePool _runspacePool ;
19
20
20
21
/// <summary>
21
22
/// Create a fresh command info cache instance.
22
23
/// </summary>
23
- public CommandInfoCache ( Helper pssaHelperInstance )
24
+ public CommandInfoCache ( Helper pssaHelperInstance , RunspacePool runspacePool )
24
25
{
25
26
_commandInfoCache = new ConcurrentDictionary < CommandLookupKey , Lazy < CommandInfo > > ( ) ;
26
27
_helperInstance = pssaHelperInstance ;
28
+ _runspacePool = runspacePool ;
27
29
}
28
30
29
31
/// <summary>
@@ -64,14 +66,16 @@ public CommandInfo GetCommandInfoLegacy(string commandOrAliasName, CommandTypes?
64
66
/// Get a CommandInfo object of the given command name
65
67
/// </summary>
66
68
/// <returns>Returns null if command does not exists</returns>
67
- private static CommandInfo GetCommandInfoInternal ( string cmdName , CommandTypes ? commandType )
69
+ private CommandInfo GetCommandInfoInternal ( string cmdName , CommandTypes ? commandType )
68
70
{
69
71
// 'Get-Command ?' would return % for example due to PowerShell interpreting is a single-character-wildcard search and not just the ? alias.
70
72
// For more details see https://github.com/PowerShell/PowerShell/issues/9308
71
73
cmdName = WildcardPattern . Escape ( cmdName ) ;
72
74
73
75
using ( var ps = System . Management . Automation . PowerShell . Create ( ) )
74
76
{
77
+ ps . RunspacePool = _runspacePool ;
78
+
75
79
ps . AddCommand ( "Get-Command" )
76
80
. AddParameter ( "Name" , cmdName )
77
81
. AddParameter ( "ErrorAction" , "SilentlyContinue" ) ;
0 commit comments