|
6 | 6 | using System;
|
7 | 7 | using System.Collections.Generic;
|
8 | 8 | using System.ComponentModel;
|
| 9 | +using System.Diagnostics.CodeAnalysis; |
9 | 10 | using System.IO;
|
10 | 11 | using System.Linq;
|
11 | 12 | using System.Management.Automation.Host;
|
|
16 | 17 | using System.Threading;
|
17 | 18 | using System.Threading.Tasks;
|
18 | 19 | using Microsoft.Extensions.Logging;
|
| 20 | +using Microsoft.PowerShell.EditorServices.Handlers; |
| 21 | +using Microsoft.PowerShell.EditorServices.Hosting; |
| 22 | +using Microsoft.PowerShell.EditorServices.Logging; |
| 23 | +using Microsoft.PowerShell.EditorServices.Services.PowerShellContext; |
19 | 24 | using Microsoft.PowerShell.EditorServices.Utility;
|
20 | 25 |
|
21 | 26 | namespace Microsoft.PowerShell.EditorServices.Services
|
22 | 27 | {
|
23 |
| - using System.Diagnostics.CodeAnalysis; |
24 | 28 | using System.Management.Automation;
|
25 |
| - using Microsoft.PowerShell.EditorServices.Handlers; |
26 |
| - using Microsoft.PowerShell.EditorServices.Hosting; |
27 |
| - using Microsoft.PowerShell.EditorServices.Services.PowerShellContext; |
28 | 29 |
|
29 | 30 | /// <summary>
|
30 | 31 | /// Manages the lifetime and usage of a PowerShell session.
|
@@ -1015,8 +1016,29 @@ public Task<IEnumerable<object>> ExecuteScriptStringAsync(
|
1015 | 1016 | {
|
1016 | 1017 | Validate.IsNotNull(nameof(scriptString), scriptString);
|
1017 | 1018 |
|
| 1019 | + PSCommand command = null; |
| 1020 | + if(CurrentRunspace.Runspace.SessionStateProxy.LanguageMode != PSLanguageMode.FullLanguage) |
| 1021 | + { |
| 1022 | + try |
| 1023 | + { |
| 1024 | + var scriptBlock = ScriptBlock.Create(scriptString); |
| 1025 | + PowerShell ps = scriptBlock.GetPowerShell(isTrustedInput: false, null); |
| 1026 | + command = ps.Commands; |
| 1027 | + } |
| 1028 | + catch (Exception e) |
| 1029 | + { |
| 1030 | + logger.LogException("Exception getting trusted/untrusted PSCommand.", e); |
| 1031 | + } |
| 1032 | + } |
| 1033 | + |
| 1034 | + // fall back to old behavior |
| 1035 | + if(command == null) |
| 1036 | + { |
| 1037 | + command = new PSCommand().AddScript(scriptString.Trim()); |
| 1038 | + } |
| 1039 | + |
1018 | 1040 | return this.ExecuteCommandAsync<object>(
|
1019 |
| - new PSCommand().AddScript(scriptString.Trim()), |
| 1041 | + command, |
1020 | 1042 | errorMessages,
|
1021 | 1043 | new ExecutionOptions()
|
1022 | 1044 | {
|
|
0 commit comments