How it works...
This process of creating a main function and calling it in the end is just so that the reader knows the ultimate intent right at the beginning of the script, and that it is not an absolute necessity.
PowerShell works on the scripts in the same manner as it does on the terminal. This is done to give a unified experience, as well as to provide script writers with the ability to test out their snippets on the terminal if they want to, or even actually run the snippets on the terminal.
You can only run those functions that have already been declared; a function that is not yet written (or read by PowerShell) cannot be run. In the case of long-running scripts with several functions, it is possible for a user to feel lost, regarding ...
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