Skip to content

$PSCmdlet.Stopping is false when stopping #6322

@alx9r

Description

@alx9r

Steps to reproduce

function a {
    param( [Parameter(ValueFromPipeline)]$InputObject )
    process {
        try { $InputObject }
        finally {
            [console]::WriteLine('a finally')
            [console]::WriteLine("a Stopping: $($PSCmdlet.Stopping)")
        }
    }
}
Add-Type '
    using System;
    using System.Management.Automation; 
    
    [Cmdlet("Invoke", "b")]
    public class b : Cmdlet 
    {
        [Parameter(ValueFromPipeline=true)]
        public object InputObject { get; set; }

        protected override void ProcessRecord()
        { 
            WriteObject(InputObject,true);
        }

        protected override void StopProcessing()
        {
            Console.WriteLine("b StopProcessing");
            Console.WriteLine("b Stopping: {0}",Stopping);
        }
    }' -PassThru | % Assembly | Import-Module
Set-Alias b Invoke-b

1 | a | b | % { sleep 10 } # press Ctrl-C here

Expected behavior

b StopProcessing
b Stopping: True
a finally
a Stopping: True

Actual behavior

b StopProcessing
b Stopping: True
a finally
a Stopping: False

Environment data

> $PSVersionTable

Name                           Value                                            
----                           -----                                            
PSVersion                      6.0.0                                            
PSEdition                      Core                                             
GitCommitId                    v6.0.0                                           
OS                             Microsoft Windows 6.3.9600                       
Platform                       Win32NT                                          
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                          
PSRemotingProtocolVersion      2.3                                              
SerializationVersion           1.1.0.1                                          
WSManStackVersion              3.0                                              

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution-No ActivityIssue has had no activity for 6 months or more

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions