Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Management.Automation.Host;
Expand All @@ -16,15 +17,15 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.PowerShell.EditorServices.Handlers;
using Microsoft.PowerShell.EditorServices.Hosting;
using Microsoft.PowerShell.EditorServices.Logging;
using Microsoft.PowerShell.EditorServices.Services.PowerShellContext;
using Microsoft.PowerShell.EditorServices.Utility;

namespace Microsoft.PowerShell.EditorServices.Services
{
using System.Diagnostics.CodeAnalysis;
using System.Management.Automation;
using Microsoft.PowerShell.EditorServices.Handlers;
using Microsoft.PowerShell.EditorServices.Hosting;
using Microsoft.PowerShell.EditorServices.Services.PowerShellContext;

/// <summary>
/// Manages the lifetime and usage of a PowerShell session.
Expand Down Expand Up @@ -1015,8 +1016,29 @@ public Task<IEnumerable<object>> ExecuteScriptStringAsync(
{
Validate.IsNotNull(nameof(scriptString), scriptString);

PSCommand command = null;
if(CurrentRunspace.Runspace.SessionStateProxy.LanguageMode != PSLanguageMode.FullLanguage)
{
try
{
var scriptBlock = ScriptBlock.Create(scriptString);
PowerShell ps = scriptBlock.GetPowerShell(isTrustedInput: false, null);
command = ps.Commands;
}
catch (Exception e)
{
logger.LogException("Exception getting trusted/untrusted PSCommand.", e);
}
}

// fall back to old behavior
if(command == null)
{
command = new PSCommand().AddScript(scriptString.Trim());
}

return this.ExecuteCommandAsync<object>(
new PSCommand().AddScript(scriptString.Trim()),
command,
errorMessages,
new ExecutionOptions()
{
Expand Down