mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Add a new experimental feature to control native argument passing style on Windows (#18706)
This commit is contained in:
@@ -28,6 +28,7 @@ namespace System.Management.Automation
|
||||
internal const string PSFeedbackProvider = "PSFeedbackProvider";
|
||||
internal const string PSCommandWithArgs = "PSCommandWithArgs";
|
||||
internal const string PSConstrainedAuditLogging = "PSConstrainedAuditLogging";
|
||||
internal const string PSWindowsNativeCommandArgPassing = "PSWindowsNativeCommandArgPassing";
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -139,7 +140,10 @@ namespace System.Management.Automation
|
||||
description: "Enable `-CommandWithArgs` parameter for pwsh"),
|
||||
new ExperimentalFeature(
|
||||
name: PSConstrainedAuditLogging,
|
||||
description: "PowerShell restriction logging when WDAC (Windows Defender Application Control) Code Integrity policy is set to Audit mode.")
|
||||
description: "PowerShell restriction logging when WDAC (Windows Defender Application Control) Code Integrity policy is set to Audit mode."),
|
||||
new ExperimentalFeature(
|
||||
name: "PSWindowsNativeCommandArgPassing",
|
||||
description: "Enable 'Windows' as the native command argument passing mode"),
|
||||
};
|
||||
|
||||
EngineExperimentalFeatures = new ReadOnlyCollection<ExperimentalFeature>(engineFeatures);
|
||||
|
||||
@@ -4534,7 +4534,7 @@ end {
|
||||
builtinVariables.Add(
|
||||
new SessionStateVariableEntry(
|
||||
SpecialVariables.NativeArgumentPassing,
|
||||
Platform.IsWindows ? NativeArgumentPassingStyle.Windows : NativeArgumentPassingStyle.Standard,
|
||||
GetPassingStyle(),
|
||||
RunspaceInit.NativeCommandArgumentPassingDescription,
|
||||
ScopedItemOptions.None,
|
||||
new ArgumentTypeConverterAttribute(typeof(NativeArgumentPassingStyle))));
|
||||
@@ -4542,6 +4542,26 @@ end {
|
||||
BuiltInVariables = builtinVariables.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Assigns the default behavior for native argument passing.
|
||||
/// If the system is non-Windows, we will return Standard.
|
||||
/// If the experimental feature is enabled, we will return Windows.
|
||||
/// Otherwise, we will return Legacy.
|
||||
/// </summary>
|
||||
private static NativeArgumentPassingStyle GetPassingStyle()
|
||||
{
|
||||
#if UNIX
|
||||
return NativeArgumentPassingStyle.Standard;
|
||||
#else
|
||||
if (ExperimentalFeature.IsEnabled(ExperimentalFeature.PSWindowsNativeCommandArgPassing))
|
||||
{
|
||||
return NativeArgumentPassingStyle.Windows;
|
||||
}
|
||||
|
||||
return NativeArgumentPassingStyle.Legacy;
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static readonly SessionStateVariableEntry[] BuiltInVariables;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -583,6 +583,11 @@ namespace System.Management.Automation
|
||||
// Get the start info for the process.
|
||||
ProcessStartInfo startInfo = GetProcessStartInfo(redirectOutput, redirectError, redirectInput, soloCommand);
|
||||
|
||||
// Send Telemetry indicating what argument passing mode we are in.
|
||||
ApplicationInsightsTelemetry.SendExperimentalUseData(
|
||||
ExperimentalFeature.PSWindowsNativeCommandArgPassing,
|
||||
NativeParameterBinderController.ArgumentPassingStyle.ToString());
|
||||
|
||||
#if !UNIX
|
||||
string commandPath = this.Path.ToLowerInvariant();
|
||||
if (commandPath.EndsWith("powershell.exe") || commandPath.EndsWith("powershell_ise.exe"))
|
||||
|
||||
Reference in New Issue
Block a user