Created
June 5, 2018 16:29
-
-
Save rjmholt/9820861c669610941a6d62b36d121fa7 to your computer and use it in GitHub Desktop.
Better PSScriptAnalyzer runspace pool creation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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