Repository: PowerShell/PowerShell
File: src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs (C#)

Code before:
                case RedirectionStream.Verbose:
                    oldPipes[(int)FromStream] = context.ExpressionVerboseOutputPipe;
                    context.ExpressionVerboseOutputPipe = pipe;
                    break;
                case RedirectionStream.Debug:
                    oldPipes[(int)FromStream] = context.ExpressionDebugOutputPipe;
                    context.ExpressionDebugOutputPipe = pipe;
                    break;
                case RedirectionStream.Information:
                    oldPipes[(int)FromStream] = context.ExpressionInformationOutputPipe;
                    context.ExpressionInformationOutputPipe = pipe;
                    break;
            }

            return oldPipes;
        }

        internal Pipe GetRedirectionPipe(ExecutionContext context, PipelineProcessor parentPipelineProcessor)
        {
            if (string.IsNullOrWhiteSpace(File))
            {
                return new Pipe { NullPipe = true };
            }

            // determine whether we're trying to set a variable by inspecting the file path
            // if we can determine that it's a variable, we'll use Set-Variable rather than Out-File
            ProviderInfo p;
            PSDriveInfo d;
            CommandProcessorBase commandProcessor;
            var name = context.SessionState.Path.GetUnresolvedProviderPathFromPSPath(File, out p, out d);

            if (ExperimentalFeature.IsEnabled("PSRedirectToVariable") && p != null && p.NameEquals(context.ProviderNames.Variable))
            {
                commandProcessor = context.CreateCommand("Set-Variable", false);
                Diagnostics.Assert(commandProcessor != null, "CreateCommand returned null");
                var cpi = CommandParameterInternal.CreateParameterWithArgument(
                    /*parameterAst*/null, "Name", "-Name:",
                    /*argumentAst*/null, name,
                    false);
                commandProcessor.AddParameter(cpi);

                if (this.Appending)
                {
                    commandProcessor.AddParameter(CommandParameterInternal.CreateParameter("Append", "-Append", null));
                }
            }
            else
            {
                commandProcessor = context.CreateCommand("out-file", false);
                Diagnostics.Assert(commandProcessor != null, "CreateCommand returned null");


Review comment (suggestion):
Just a note and not something you need to change, but it seems in the future, it would make more sense to have `Out-Provider` and have the provider subsystem determine which provider receives it rather than hardcoding to specific cases here

Code after:
                case RedirectionStream.Verbose:
                    oldPipes[(int)FromStream] = context.ExpressionVerboseOutputPipe;
                    context.ExpressionVerboseOutputPipe = pipe;
                    break;
                case RedirectionStream.Debug:
                    oldPipes[(int)FromStream] = context.ExpressionDebugOutputPipe;
                    context.ExpressionDebugOutputPipe = pipe;
                    break;
                case RedirectionStream.Information:
                    oldPipes[(int)FromStream] = context.ExpressionInformationOutputPipe;
                    context.ExpressionInformationOutputPipe = pipe;
                    break;
            }

            return oldPipes;
        }

        internal Pipe GetRedirectionPipe(ExecutionContext context, PipelineProcessor parentPipelineProcessor)
        {
            if (string.IsNullOrWhiteSpace(File))
            {
                return new Pipe { NullPipe = true };
            }

            // determine whether we're trying to set a variable by inspecting the file path
            // if we can determine that it's a variable, we'll use Set-Variable rather than Out-File
            ProviderInfo p;
            PSDriveInfo d;
            CommandProcessorBase commandProcessor;
            var name = context.SessionState.Path.GetUnresolvedProviderPathFromPSPath(File, out p, out d);

            if (ExperimentalFeature.IsEnabled(ExperimentalFeature.PSRedirectToVariable) && p != null && p.NameEquals(context.ProviderNames.Variable))
            {
                commandProcessor = context.CreateCommand("Set-Variable", false);
                Diagnostics.Assert(commandProcessor != null, "CreateCommand returned null");
                var cpi = CommandParameterInternal.CreateParameterWithArgument(
                    /*parameterAst*/null, "Name", "-Name:",
                    /*argumentAst*/null, name,
                    false);
                commandProcessor.AddParameter(cpi);

                if (this.Appending)
                {
                    commandProcessor.AddParameter(CommandParameterInternal.CreateParameter("Append", "-Append", null));
                }
            }
            else
            {
                commandProcessor = context.CreateCommand("out-file", false);
                Diagnostics.Assert(commandProcessor != null, "CreateCommand returned null");