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

Redirection operators


In Chapter 4, Working with Objects in PowerShell, we started exploring the different output streams PowerShell utilizes.

Information from a command may be redirected using the redirection operator >. Information may be sent to another stream or a file.

For example, the output from a command can be directed to a file. The file will contain the output as it would have been displayed in the console:

PS> Get-Process -Id $pid > process.txt
Get-Content process.txt 

Handles NPM(K)  PM(K)  WS(K) CPU(s)    Id SI  ProcessName 
------- ------  -----  ----- ------    -- --  ----------- 
    731     57 132264 133156   1.81 11624  1  powershell_ise

Each of the streams in PowerShell has a number associated with it. These are shown in the following table:

Stream name

Stream number

Standard out

1

Error

2

Warning

3

Verbose

4

Debug

5

Information

6

Note

About Write-Host:Before PowerShell 5, the output written using the Write-Host command could not be captured, redirected, or assigned to a variable...