Book Image

Mastering PowerShell Scripting - Fourth Edition

By : Chris Dent
5 (1)
Book Image

Mastering PowerShell Scripting - Fourth Edition

5 (1)
By: Chris Dent

Overview of this book

PowerShell scripts offer a convenient way to automate various tasks, but working with them can be daunting. Mastering PowerShell Scripting takes away the fear and helps you navigate through PowerShell's capabilities.This extensively revised edition includes new chapters on debugging and troubleshooting and creating GUIs (online chapter). Learn the new features of PowerShell 7.1 by working with parameters, objects, and .NET classes from within PowerShell 7.1. This comprehensive guide starts with the basics before moving on to advanced topics, including asynchronous processing, desired state configuration, using more complex scripts and filters, debugging issues, and error-handling techniques. Explore how to efficiently manage substantial amounts of data and interact with other services using PowerShell 7.1. This book will help you to make the most of PowerShell's automation features, using different methods to parse data, manipulate regular expressions, and work with Windows Management Instrumentation (WMI).
Table of Contents (26 chapters)
24
Other Books You May Enjoy
25
Index

Regex options

Regular expression options are used to control the behavior of certain characters in an expression.

Some aspects of the behavior of a regular expression can be modified by placing a regex option either at the beginning or around part of an expression.

In the following example, .+ will only match the first line; the result of the whole match is in the 0 key in the $matches Hashtable:

PS> "First line`nSecond line" -match '.+'
True
PS> $matches[0]
First line

This is because dot (.) will not match line break characters by default. You can change this by setting a single-line option for the expression:

PS> "First line`nSecond line" -match '(?s).+'
True
PS> $matches[0]
First line
Second line

Table 9.7 shows various regex options and their effect:

...

Character

Description