Let's just say for argument's sake that you wanted to create a PowerShell Cmdlet that gets all of the files in your current directory and print their names to the console. Assuming that the class which is supposed to do all of this inherits from PSCmdlet, would you put the logic into ProcessRecord or EndProcessing? The tutorial I've been looking places the main code in EndProcess. I was curious to know if placing the that code in ProcessRecord would change anything.
1 Answer
Here a summary of methods:
BeginProcessing = Provides a one-time, preprocessing functionality for the cmdlet.
EndProcessing = Provides a one-time, post-processing functionality for the cmdlet.
ProcessRecord = Provides a record-by-record processing functionality for the cmdlet.
In the case of your link the cmdlet logic is in EndProcessing method because is doing a one-shot action.
Move the logic in ProcessRecord() don't change the result but is not logically correct.
Read here for more info.