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

Other operators

PowerShell has a wide variety of operators, a few of which do not easily fall into a specific category:

  • Call: &
  • Comma: ,
  • Format: -f
  • Increment and decrement: ++ and --
  • Join: -join

Each of these operators is in common use. The call operator can run a command based on a string, to the format operator which can be used to build up complex strings, and so on.

Call

The call operator (&) is used to execute a string or script block. The call operator is particularly useful when running commands (executables or scripts) that have spaces in the path. The call operator is also useful if the command name changes based on circumstances, for example, the operating system running a command.

The following example runs pwsh.exe using a full path held in a string:

& 'C:\Program Files\PowerShell\7\pwsh.exe'

The path to pwsh.exe is normally in the PATH environment variable, using the full path...