Skip to content

Commit c2b64ff

Browse files
committed
Always allow PSScriptAnalzyer to load
1 parent ee6fdc5 commit c2b64ff

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/PowerShellEditorServices/Services/Analysis/PssaCmdletAnalysisEngine.cs

+9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System.Threading.Tasks;
1111
using Microsoft.Extensions.Logging;
1212
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
13+
using Microsoft.PowerShell.EditorServices.Utility;
1314

1415
namespace Microsoft.PowerShell.EditorServices.Services.Analysis
1516
{
@@ -360,6 +361,14 @@ private static RunspacePool CreatePssaRunspacePool(string pssaModulePath)
360361
// We intentionally use `CreateDefault2()` as it loads `Microsoft.PowerShell.Core`
361362
// only, which is a more minimal and therefore safer state.
362363
InitialSessionState sessionState = InitialSessionState.CreateDefault2();
364+
365+
// We set the runspace's execution policy `Bypass` so we can always import our bundled
366+
// PSScriptAnalyzer module.
367+
if (VersionUtils.IsWindows)
368+
{
369+
sessionState.ExecutionPolicy = ExecutionPolicy.Bypass;
370+
}
371+
363372
sessionState.ImportPSModulesFromPath(pssaModulePath);
364373

365374
RunspacePool runspacePool = RunspaceFactory.CreateRunspacePool(sessionState);

0 commit comments

Comments
 (0)