Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Cmdlet.EndProcessing and Cmdlet.StopProcessing

When writing Powershell cmdlets, what is the difference between EndProcessing and StopProcessing? They sound the same, their descriptions are just about the same, and latter doesn't appear in the cmdlet lifecycle documentation.

like image 585
Justin R. Avatar asked Oct 27 '09 00:10

Justin R.


People also ask

What are the two parts that make up a cmdlet name?

Cmdlet Names PowerShell uses a verb-and-noun name pair to name cmdlets. For example, the Get-Command cmdlet included in PowerShell is used to get all the cmdlets that are registered in the command shell.

How do I list all cmdlets in PowerShell?

Use CommandType or its alias, Type. By default, Get-Command gets all cmdlets, functions, and aliases. The acceptable values for this parameter are: Alias : Gets the aliases of all PowerShell commands.

What does cmdlet stand for?

A cmdlet -- pronounced command-let -- is a small, lightweight command that is used in the Windows PowerShell environment. A cmdlet typically exists as a small script that is intended to perform a single specific function such as coping files and changing directories.


1 Answers

StopProcessing is called if the execution of the CmdLet is cancelled (pressing CNTRL-C will cause StopProcessing to be executed).

EndProcessing is called if the execution of the CmdLet ends normally.

I typically use StopProcessing and EndProcessing to do the same thing... that is to clean up resources that were provisioned during BeginProcessing or ProcessRecord, in some cases though there is some difference between what actions each provides.

It seems like a mistake that it is not shown in the life cycle documentation.

like image 153
Eric Schoonover Avatar answered Oct 01 '22 22:10

Eric Schoonover