Skip to content

Commit

Permalink
Always allow PSScriptAnalzyer to load
Browse files Browse the repository at this point in the history
  • Loading branch information
andyleejordan committed Dec 8, 2023
1 parent 2c4fa04 commit 118eea9
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
using Microsoft.PowerShell.EditorServices.Utility;

namespace Microsoft.PowerShell.EditorServices.Services.Analysis
{
Expand Down Expand Up @@ -360,6 +361,14 @@ private static RunspacePool CreatePssaRunspacePool(string pssaModulePath)
// We intentionally use `CreateDefault2()` as it loads `Microsoft.PowerShell.Core`
// only, which is a more minimal and therefore safer state.
InitialSessionState sessionState = InitialSessionState.CreateDefault2();

// We set the runspace's execution policy `Bypass` so we can always import our bundled
// PSScriptAnalyzer module.
if (VersionUtils.IsWindows)
{
sessionState.ExecutionPolicy = ExecutionPolicy.Bypass;
}

sessionState.ImportPSModulesFromPath(pssaModulePath);

RunspacePool runspacePool = RunspaceFactory.CreateRunspacePool(sessionState);
Expand Down

0 comments on commit 118eea9

Please sign in to comment.