locked
Powershell : Cmdlets throwing a PipelineStoppedException RRS feed

  • Question

  • I have a cmdlet named update-name which throws a ThrowTerminatingError when it encounters an exception. This works fine. But when I do get-name | update-name and if in this case an error occurs, it results in an exception :

    System.Management.Automation.PipelineStoppedException: The pipeline has been stopped.
       at System.Management.Automation.CommandProcessor.ProcessRecord()
       at System.Management.Automation.CommandProcessorBase.DoExecute()
       at System.Security.SecurityContext.Run(SecurityContext securityContext, ContextCallback callback, Object state)
       at System.Management.Automation.MshCommandRuntime.WriteObject(Object sendToPi
    peline)
       at System.Management.Automation.Cmdlet.WriteObject(Object sendToPipeline)

    Thus the exception is shown on the screen only when the input is given from a pipeline. Otherwise it works fine. I am not able to understand this behaviour. Can somebody help?

    • Moved by Bill_Stewart Monday, July 7, 2014 7:09 PM Abandoned
    Friday, March 28, 2014 5:20 AM

All replies

  • Yes.  A terminating exception will stop a pipeline.  Without your script we cannot guess any further.


    ¯\_(ツ)_/¯

    Friday, March 28, 2014 12:38 PM
  • Per MSDN (http://msdn.microsoft.com/en-us/library/system.management.automation.pipelinestoppedexception(v=vs.85).aspx ):

    The exception that is thrown when a cmdlet or a Windows PowerShell provider attempts to write to the pipeline or perform a number of other Windows PowerShell operations after the pipeline has been terminated. The pipeline could have been terminated before the call was made or during the call.

    Cmdlets and providers do not have to catch this exception unless they have cleanup operations to perform. They can simply allow this exception to propagate up, and the Windows PowerShell runtime will catch the exception.

    Friday, March 28, 2014 1:47 PM