Preface
If you are a system administrator who manages a considerable-sized environment, then I do not need to elaborate on the importance of scripting to you. Scripting was and always will be one of the most important arsenals in a system administrator's weaponry. With the term scripting, till very recently typically bash or other such shell scripts used to come to mind and more advanced ones, such as Perl, PHP, or Ruby. I love this scripting language for the sheer beauty and power that it presents. If you are coming from a *NIX environment, PowerShell will completely change your perception about scripting. If you are managing a vSphere environment, then besides vRealize Orchestrator, PowerCLI is the most powerful tool available to help you automate the different aspects of a vSphere environment. Probably, if I need to get something done really quickly, I will still rely on PowerCLI scripting.
In all my years of experience as a working professional and before that as a student and teacher, I have seen primarily two methods of explanation: the first approach, and the most widely used one, is to take an example problem and solve it while explaining the solution to the student. This way, the student learns how to solve a particular type of problem. The second approach is the one in which a teacher explains the basic logic and principles of a solution behind the problem, and then asks the students to solve the problem all by themselves. As a student, I always found myself struggling with the first approach. Though the first approach was easier to understand, it tends to limit my knowledge to solving only similar problems. Because of the lack of the understanding of the underlying logic, faced with a new problem, I could not solve it most of the time. This happened especially in mathematical problems. It was like showing me a program written in C to implement Dijkstra's algorithm and explaining how this program was written. Knowing this, will I be able to implement any other algorithm in C or utilize Dijkstra's algorithm for my advantage? Probably not. Instead, if someone teaches me the different aspects of C language and how to write programs using C, then I can utilize this knowledge to write any programs.
You may disagree or agree with me, but I always preferred the second approach as it worked for me and gave me a better understanding and hold on the topic.
So, throughout this book, I tried to explain all the building blocks of advanced PowerShell and PowerCLI scripting and then provided examples to showcase what I am trying to say. I tried this approach with the hope that it will give you a better understanding and clarity of the underlying constructs so that you can build on top of this.