8000 Revert "Add `-StrictMode` to `Invoke-Command` to allow specifying strict mode when invoking command locally" by SteveL-MSFT · Pull Request #18040 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Revert "Add -StrictMode to Invoke-Command to allow specifying strict mode when invoking command locally" #18040

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion experimental-feature-linux.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
"PSCommandNotFoundSuggestion",
"PSLoadAssemblyFromNativeCode",
"PSNativeCommandErrorActionPreference",
"PSStrictModeAssignment",
"PSSubsystemPluginModel"
]
1 change: 0 additions & 1 deletion experimental-feature-windows.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
"PSCommandNotFoundSuggestion",
"PSLoadAssemblyFromNativeCode",
"PSNativeCommandErrorActionPreference",
"PSStrictModeAssignment",
"PSSubsystemPluginModel"
]
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class ExperimentalFeature

internal const string EngineSource = "PSEngine";
internal const string PSNativeCommandErrorActionPreferenceFeatureName = "PSNativeCommandErrorActionPreference";
internal const string PSStrictModeAssignment = "PSStrictModeAssignment";

#endregion

Expand Down Expand Up @@ -120,9 +119,6 @@ static ExperimentalFeature()
new ExperimentalFeature(
name: PSNativeCommandErrorActionPreferenceFeatureName,
description: "Native commands with non-zero exit codes issue errors according to $ErrorActionPreference when $PSNativeCommandUseErrorActionPreference is $true"),
new ExperimentalFeature(
name: PSStrictModeAssignment,
description: "Add support of setting Strict-Mode with Invoke-Command"),
};

EngineExperimentalFeatures = new ReadOnlyCollection<ExperimentalFeature>(engineFeatures);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,72 +263,6 @@ public override SwitchParameter UseSSL
}
}

private sealed class ArgumentToPSVersionTransformationAttribute : ArgumentToVersionTransformationAttribute
{
protected override bool TryConvertFromString(string versionString, [NotNullWhen(true)] out Version version)
{
if (string.Equals("off", versionString, StringComparison.OrdinalIgnoreCase))
{
version = new Version(0, 0);
return true;
}

if (string.Equals("latest", versionString, StringComparison.OrdinalIgnoreCase))
{
version = PSVersionInfo.PSVersion;
return true;
}

return base.TryConvertFromString(versionString, out version);
}
}

private static readonly Version s_OffVersion = new Version(0, 0);

private sealed class ValidateVersionAttribute : ValidateArgumentsAttribute
{
protected override void Validate(object arguments, EngineIntrinsics engineIntrinsics)
{
Version version = arguments as Version;
if (version == s_OffVersion)
{
return;
}

if (version == null || !PSVersionInfo.IsValidPSVersion(version))
{
// No conversion succeeded so throw an exception...
throw new ValidationMetadataException(
"InvalidPSVersion",
null,
Metadata.ValidateVersionFailure,
arguments);
}
}
}

/// <summary>
/// Gets or sets strict mode.
/// </summary>
[Experimental(ExperimentalFeature.PSStrictModeAssignment, ExperimentAction.Show)]
[Parameter(ParameterSetName = InvokeCommandCommand.InProcParameterSet)]
[ArgumentToPSVersionTransformation]
[ValidateVersion]
public Version StrictMode
{
get
{
return _strictmodeversion;
}

set
{
_strictmodeversion = value;
}
}

private Version _strictmodeversion = null;

/// <summary>
/// For WSMan session:
/// If this parameter is not specified then the value specified in
Expand Down Expand Up @@ -908,8 +842,6 @@ public virtual SwitchParameter RemoteDebug

#endregion

private Version _savedStrictModeVersion;

#endregion Parameters

#region Overrides
Expand Down Expand Up @@ -1033,12 +965,6 @@ protected override void BeginProcessing()
}
}

if (_strictmodeversion != null)
{
_savedStrictModeVersion = Context.EngineSessionState.CurrentScope.StrictModeVersion;
Context.EngineSessionState.CurrentScope.StrictModeVersion = _strictmodeversion;
}

return;
}

Expand Down Expand Up @@ -1255,19 +1181,7 @@ protected override void ProcessRecord()
}
else if (ParameterSetName.Equals(InvokeCommandCommand.InProcParameterSet) && (_steppablePipeline != null))
{
try
{
_steppablePipeline.Process(InputObject);
}
catch
{
if (_strictmodeversion != null)
{
Context.EngineSessionState.CurrentScope.StrictModeVersion = _savedStrictModeVersion;
}

throw;
}
_steppablePipeline.Process(InputObject);
}
else
{
Expand Down Expand Up @@ -1298,30 +1212,20 @@ protected override void EndProcessing()
{
if (ParameterSetName.Equals(InvokeCommandCommand.InProcParameterSet))
{
try
{
if (_steppablePipeline != null)
{
_steppablePipeline.End();
}
else
{
ScriptBlock.InvokeUsingCmdlet(
contextCmdlet: this,
useLocalScope: !NoNewScope,
errorHandlingBehavior: ScriptBlock.ErrorHandlingBehavior.WriteToCurrentErrorPipe,
dollarUnder: AutomationNull.Value,
input: _input,
scriptThis: AutomationNull.Value,
args: ArgumentList);
}
if (_steppablePipeline != null)
{
_steppablePipeline.End();
}
finally
else
{
if (_strictmodeversion != null)
{
Context.EngineSessionState.CurrentScope.StrictModeVersion = _savedStrictModeVersion;
}
ScriptBlock.InvokeUsingCmdlet(
contextCmdlet: this,
useLocalScope: !NoNewScope,
errorHandlingBehavior: ScriptBlock.ErrorHandlingBehavior.WriteToCurrentErrorPipe,
dollarUnder: AutomationNull.Value,
input: _input,
scriptThis: AutomationNull.Value,
args: ArgumentList);
}
}
else
Expand Down

This file was deleted.

0