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

System.Xml.Linq


The System.Xml.Linq namespace was added with .NET 3.5. This is known as LINQ to XML. Language Integrated Query (LINQ) is used to describe a query in the same language as the rest of a program. Therefore, interacting with a complex XML document does not require the use of XPath queries.

PowerShell can make use of System.Xml.Linq once the required assembly has been added:

Add-Type -AssemblyName System.Xml.Linq 

This can also be phrased as:

using assembly System.Xml.Linq

As a newer interface, System.Xml.Linq tends to be more consistent. The same syntax is used to create a document from scratch that is used to add elements and so on.

Opening documents

The XDocument class is used to load or parse a document. XML content may be cast to an XDocument in the same way that content is cast using the [Xml] type accelerator:

using assembly System.Xml.Linq 
[System.Xml.Linq.XDocument]$xDocument = @" 
<?xml version="1.0"?> 
<cars> 
<car type="Saloon"> 
<colour>Green<...