Skip to content

Instantly share code, notes, and snippets.

@rjmholt
Created June 5, 2018 16:29
Show Gist options
  • Save rjmholt/9820861c669610941a6d62b36d121fa7 to your computer and use it in GitHub Desktop.
Save rjmholt/9820861c669610941a6d62b36d121fa7 to your computer and use it in GitHub Desktop.
Better PSScriptAnalyzer runspace pool creation
private static RunspacePool CreatePssaRunspacePool()
{
// Use public but unfriendly APIs to import a PSScriptAnalyzer module with the needed minimum version
var pssaModuleSpec = new ModuleSpecification(new Hashtable()
{
{ "ModuleName", PSSA_MODULE_NAME },
{ "ModuleVersion", s_pssaMinimumVersion }
});
// Create a base session state with PSScriptAnalyzer loaded
InitialSessionState sessionState = InitialSessionState.CreateDefault2();
sessionState.ImportPSModule(new [] { pssaModuleSpec });
// RunspacePool takes care of queuing commands for us so we do not
// need to worry about executing concurrent commands
return RunspaceFactory.CreateRunspacePool(sessionState);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment