How it works...
The begin block contains a block of code that runs once per function call. Going by this method, the begin block will execute once, and then the entire process block will run for each of the objects passed into the function (either as a parameter, or via the pipeline).
Whatever is in the process block is the actual code for the function. This executes once for each object in the pipeline. We did not use the end block for this recipe, but it can be used if you would like your function to perform a post-processing step.
Typically, in production environments, we use the begin block to handle prerequisites, such as loading a certain module that is required in the process block. We add these steps in a try–catch block, with the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access