Book Image

Mastering Windows PowerShell Scripting - Third Edition

By : Chris Dent
Book Image

Mastering Windows PowerShell Scripting - Third Edition

By: Chris Dent

Overview of this book

PowerShell scripts offer a handy way to automate various chores, however working effectively with these scripts can be a difficult task. This comprehensive guide starts with the fundamentals before moving on to advanced-level topics to help you become a PowerShell Core 6.0 expert. The first module, PowerShell Core 6.0 Fundamentals, begins with the new features of PowerShell Core 6.0, installing it on Linux, and working with parameters, objects and .NET classes from within PowerShell Core 6.0. As you make your way through the chapters, you'll see how to efficiently manage large amounts of data and interact with other services using PowerShell Core 6.0. You'll be able to make the most of PowerShell Core 6.0's powerful automation feature, where you will have different methods available to parse data and manipulate regular expressions and Windows Management Instrumentation (WMI). After having explored automation, you will enter the extending PowerShell Core 6.0 module, covering asynchronous processing and desired state configuration. In the last module, you will learn to extend PowerShell Core 6.0 using advanced scripts and filters, and also debug issues along with working on error handling techniques. By the end of this book, you will be an expert in scripting with PowerShell Core 6.0.
Table of Contents (27 chapters)
Free Chapter
1
Section 1: Exploring PowerShell Fundamentals
6
Section 2: Working with Data
16
Section 3: Automating with PowerShell
19
Section 4: Extending PowerShell

What this book covers

Chapter 1, Introduction to PowerShell, offers a brief introduction to some of the most important parts of PowerShell. Including the help subsystem, command naming, providers, and splatting.

Chapter 2, Modules and Snap-Ins, explores the use of modules in PowerShell and PowerShell Core, followed by a brief look at snap-ins in Windows PowerShell.

Chapter 3, Working with Objects in PowerShell, explores the different commands available to interact with objects. These utility commands are used again and again.

Chapter 4, Operators, takes a look at the different operators available in PowerShell. Operators are a fundamental part of life in PowerShell.

Chapter 5, Variables, Arrays, and Hashtables, takes a deep dive into the use of variables within PowerShell, including concepts such as variable scope.

Chapter 6, Branching and Looping, explores different loop operators, such as foreach, for, while, and do.

Chapter 7, Working with .NET, focuses on what .NET means to PowerShell and takes a look at type accelerators and the new using keyword.

Chapter 8, Strings, Numbers, and Dates, explores working with some of the most common datatypes in PowerShell.

Chapter 9, Regular Expressions, takes a look at the use of regular expressions in PowerShell with a number of detailed examples.

Chapter 10, Files, Folders, and the Registry, explains that working with the filesystem is an important part of any scripting language. The registry has long been a core part of the Microsoft operating system. This chapter takes a look at the commands used to interact with both the filesystem and the registry.

Chapter 11, Windows Management Instrumentation, explains that when there are no specific commands, WMI is often the first stop. This chapter explores the commands used to interact with WMI.

Chapter 12, HTML, XML, and JSON, are common text-based formats that must be either generated or interrogated using PowerShell. This chapter looks at some of the methods available and a number of the common pitfalls.

Chapter 13, Web Requests and Web Services, explains that the last 5 years has seen the use of web services, particularly REST, soar. This chapter takes a good look at working with REST, using GitHub as a reference site. SOAP is explored in Windows PowerShell using a custom-built site.

Chapter 14, Remoting and Remote Management, covers PowerShell remoting, which is an import tool stretching PowerShell out from a local machine. The introduction of PowerShell Core adds the ability to use PowerShell remoting to Mac and Linux machines.

Chapter 15, Asynchronous Processing, starts off with a brief exploration of jobs before taking a look at events and, finally, Runspace Pools.

Chapter 16, Scripts, Functions, and Filters, covers the building blocks of larger scripts and modules. This chapter explores the structure of scripts and functions and the use of named blocks in relation to the pipeline.

Chapter 17, Parameters, Validation, and Dynamic Parameters, explores the param block in PowerShell. The param block is incredibly versatile, allowing immediately input validation, and offering features such as argument completion.

Chapter 18, Classes and Enumerations, explores classes in PowerShell and showcases a few possible uses of classes, including parameter validation, argument transformation, and class-based DSC resources.

Chapter 19, Building Modules, explains that a module draws together groups of functions into a single unit. This chapter also explores differences in structure and requirements between development and runtime.

Chapter 20, Testing, explores static analysis and unit testing using Pester. Testing requires a great deal of practice but can be used to offer confidence that a script or function behaves they way it was intended to.

Chapter 21, Error Handling, explores the different types of errors in PowerShell and how they might be handled. This chapter includes the use of try, catch, finally, and trap.