Book Image

Mastering Windows PowerShell Scripting (Second Edition) - Second Edition

By : Brenton J.W. Blawat
Book Image

Mastering Windows PowerShell Scripting (Second Edition) - Second Edition

By: Brenton J.W. Blawat

Overview of this book

PowerShell scripts offer a handy way to automate various chores. Working with these scripts effectively can be a difficult task. This comprehensive guide starts from scratch and covers advanced-level topics to make you a PowerShell expert. The first module, PowerShell Fundamentals, begins with new features, installing PowerShell on Linux, working with parameters and objects, and also how you can work with .NET classes from within PowerShell. In the next module, you’ll see how to efficiently manage large amounts of data and interact with other services using PowerShell. You’ll be able to make the most of PowerShell’s powerful automation feature, where you will have different methods to parse and manipulate data, regular expressions, and WMI. After automation, you will enter the Extending PowerShell module, which covers topics such as asynchronous processing and, creating modules. The final step is to secure your PowerShell, so you will land in the last module, Securing and Debugging PowerShell, which covers PowerShell execution policies, error handling techniques, and testing. By the end of the book, you will be an expert in using the PowerShell language.
Table of Contents (24 chapters)
Title Page
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Repetition


A quantifier is used to repeat an element; three of the quantifiers have already been introduced: *, +, and ?. The quantifiers are as follows:

Description

Character

Example

The preceding character repeated zero or more times

*

'abc'-match 'a*'

'abc'-match '.*'

The preceding character repeated one or more times

+

'abc'-match 'a+'

'abc'-match '.+'

Optional character

?

'abc' -match 'ab?c'

'ac' -match 'ab?c'

A fixed number of characters

{exactly}

'abbbc' -match 'ab{3}c'

A number of characters within a range

{min,max}

'abc' -match 'ab{1,3}c'

'abbc' -match 'ab{1,3}c'

'abbbc' -match 'ab{1,3}c'

No less than a number of characters

{min,}

'abbc' -match 'ab{2,}c'

'abbbbbc' -match 'ab{2,}c'

Each *, +, and ? can be described using a curly brace notation:

  • * is the same as {0,}
  • + is the same as {1,}
  • ? is the same as {0,1}

It is extremely uncommon to find examples where the functionality of special characters is replaced with curly braces. It is equally uncommon to find examples where the quantifier {1} is used as it adds unnecessary...