Read an Excerpt
INTRODUCTION
Throughout my career in IT, I’ve worked a diverse range of jobs: I’ve been in the trenches answering calls on the help desk, visited users to tell them to reboot as a technician, kept servers up as a systems administrator, designed and built solutions as a systems engineer, and learned the difference between OSPF and RIP routing as a network engineer.
It wasn’t until I discovered PowerShell that I realized how passionate I could be for a particular technology. PowerShell has changed my life in more ways than one, and it’s the technology that’s changed the trajectory of my career most dramatically. This language helped me be a critical asset at my job by knowing how to save countless hours of my team’s work, and it got me my first six-figure salary. PowerShell is just so cool that I decided I had to share it with the world, and since then, I’ve been awarded the prestigious Microsoft MVP award for five years straight.
In this book, I’ll show you how to use PowerShell to automate thousands of tasks, build custom tools instead of buying off-the-shelf products, and link various tools together. You may not be interested in becoming an active member of the PowerShell community, but I guarantee that learning PowerShell will give you skills that many businesses need and actively seek.
Why PowerShell?
Once called Monad (see https://www.jsnover.com/Docs/MonadManifesto.pdf ) and pitched as a more intuitive way to automate tasks than VBScript in 2003, Microsoft PowerShell is a universal automation, scripting, and development language. PowerShell was created to bridge the gap between scripting, automation, and operations personnel. It was meant to enable users to automate tasks with scripts without having to learn computer programming. This makes it particularly useful for system administrators who lack a background in software development. If you’re a system administrator with not enough time to get everything done, PowerShell is a great ally to have.
PowerShell has now become an open source, ubiquitous, cross-platform scripting and development language. You can use PowerShell not only to provision fully configured server farms, but also to create a text file or set a registry key. Thousands of software products and services have PowerShell support now, thanks to its ever-increasing adoption rate among IT professionals, developers, DevOps engineers, database administrators, and systems engineers.
Who This Book Is For
This book is for IT professionals and system administrators who are tired of clicking around in the same GUI and performing the same task for the 500th time this year. It can also be for DevOps engineers who are struggling to automate new server environments, perform automated testing, or automate an entire continuous integration/continuous delivery (CI/CD) build pipeline.
No single demographic benefits the most from PowerShell. The traditional job role of a PowerShell user is the Microsoft system administrator in a “Windows shop,” but PowerShell tends to fit well in the tool belt of any IT operations personnel. If you’re in IT and don’t consider yourself a developer, this book is for you.
About This Book
In this book, I’ll teach by doing, using tons of examples and real-world use cases. Instead of telling you what a variable is, I’ll show you. If you’re looking for a traditional textbook, this book isn’t for you.
I won’t break PowerShell into parts and cover each feature independently, since that’s not how you’ll use PowerShell in the real world. For example, rather than expect you to know the written definition of a function or for loop, I’ll combine features whenever possible to give you a holistic understanding of the problem at hand and how to solve it.
The book is divided into three parts.
Part I: Fundamentals gives PowerShell newcomers the knowledge they need to hang with the seasoned veterans. If you’re at an intermediate or higher skill level in PowerShell, you can skip to Chapter 8.
Chapters 1–7 cover the PowerShell language itself. You’ll learn the basics including how to find help and how to discover new commands, as well as some programming concepts common to other programming languages such as variables, objects, functions, modules, and errorhandling basics.
Chapter 8 explains how to use PowerShell remoting to connect to and run commands on remote computers.
Chapter 9 introduces the popular PowerShell testing framework Pester, which you’ll use throughout the book.
In Part II: Automating Day-to-Day Tasks, you’ll apply what you learned in Part I to begin automating common tasks.
Chapters 10–13 cover how to parse structured data as well as common domains many IT administrators work with, such as Active Directory, Azure, and Amazon Web Services (AWS).
Chapter 14 shows you how to build a tool you can use in your own environment to inventory your servers.
In Part III: Building Your Own Module, you’ll focus on building a single PowerShell module called PowerLab to demonstrate what’s possible with PowerShell. We’ll cover good module design and best practices around functions. Even if you consider yourself an advanced PowerShell scripter, you’re sure to learn something from Part III.
Chapters 15–20 explain how to use PowerShell to automate entire lab or test server environments by demonstrating how to provision Hyper-V virtual machines, install operating systems, and deploy and configure IIS and SQL servers.
I hope this book helps you get your feet wet with PowerShell. If you’re a beginner, I hope it gives you the courage to start automating; if you’re a seasoned scripter, I hope it shows you some tricks you may not be familiar with.
Let’s get scripting!