Skip to content

Commit 88a21e4

Browse files
Run script in local scope to make PSReadLine works in PSES in ConstrainedLanguageMode (#1527)
1 parent 2463620 commit 88a21e4

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

PSReadLine/ReadLine.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ internal static PSKeyInfo ReadKey()
230230
if (ps == null)
231231
{
232232
ps = System.Management.Automation.PowerShell.Create(RunspaceMode.CurrentRunspace);
233-
ps.AddScript("0");
233+
ps.AddScript("0", useLocalScope: true);
234234
}
235235

236236
// To detect output during possible event processing, see if the cursor moved
@@ -653,7 +653,7 @@ private PSConsoleReadLine()
653653
{
654654
try
655655
{
656-
var results = ps.AddScript("$Host").Invoke<PSHost>();
656+
var results = ps.AddScript("$Host", useLocalScope: true).Invoke<PSHost>();
657657
PSHost host = results.Count == 1 ? results[0] : null;
658658
hostName = host?.Name;
659659
}

0 commit comments

Comments
 (0)