55using System . Collections . Concurrent ;
66using System . Management . Automation ;
77using System . Linq ;
8+ using System . Management . Automation . Runspaces ;
89
910namespace Microsoft . Windows . PowerShell . ScriptAnalyzer
1011{
@@ -14,16 +15,17 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer
1415 internal class CommandInfoCache
1516 {
1617 private readonly ConcurrentDictionary < CommandLookupKey , Lazy < CommandInfo > > _commandInfoCache ;
17-
1818 private readonly Helper _helperInstance ;
19+ private readonly RunspacePool _runspacePool ;
1920
2021 /// <summary>
2122 /// Create a fresh command info cache instance.
2223 /// </summary>
23- public CommandInfoCache ( Helper pssaHelperInstance )
24+ public CommandInfoCache ( Helper pssaHelperInstance , RunspacePool runspacePool )
2425 {
2526 _commandInfoCache = new ConcurrentDictionary < CommandLookupKey , Lazy < CommandInfo > > ( ) ;
2627 _helperInstance = pssaHelperInstance ;
28+ _runspacePool = runspacePool ;
2729 }
2830
2931 /// <summary>
@@ -64,14 +66,16 @@ public CommandInfo GetCommandInfoLegacy(string commandOrAliasName, CommandTypes?
6466 /// Get a CommandInfo object of the given command name
6567 /// </summary>
6668 /// <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 )
6870 {
6971 // 'Get-Command ?' would return % for example due to PowerShell interpreting is a single-character-wildcard search and not just the ? alias.
7072 // For more details see https://github.com/PowerShell/PowerShell/issues/9308
7173 cmdName = WildcardPattern . Escape ( cmdName ) ;
7274
7375 using ( var ps = System . Management . Automation . PowerShell . Create ( ) )
7476 {
77+ ps . RunspacePool = _runspacePool ;
78+
7579 ps . AddCommand ( "Get-Command" )
7680 . AddParameter ( "Name" , cmdName )
7781 . AddParameter ( "ErrorAction" , "SilentlyContinue" ) ;
0 commit comments