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

Implicit Boolean

A value that is not Boolean but is tested as if it were true or false is an implicit Boolean. For example, the following if statement tests the output from a command:

if (Get-ChildItem c:\users\a*) {
    # If statement body
}

The condition evaluates as true when the Get-ChildItem command finds one or more files or folders. The condition evaluates as false when no files or folders are found.

An explicit version of the same comparison is shown here:

if ($null -ne (Get-ChildItem c:\users\c*)) {
    # If statement body
}

The previous explicit statement is clearly more complex and more difficult to read.

A condition with no comparison operator implicitly evaluates to false if it is any of the following:

  • $null
  • An empty string
  • An empty array
  • The numeric value 0

A variable containing a single object, or an array containing one or more elements, and so on evaluate to true.