Book Image

Windows PowerShell for .NET Developers - Second Edition - Second Edition

Book Image

Windows PowerShell for .NET Developers - Second Edition - Second Edition

Overview of this book

Windows PowerShell 5.0 for .NET Developers is your self-start guide to performing automation using Windows PowerShell. This book will help you to understand the PowerShell syntax and grammar and will also teach you techniques to remove the rough edges of manual deployments. Packed with PowerShell scripts and sample C# codes to automate tasks, it also includes real-world scenarios such as administrating office servers to help you save time and perform deployments swiftly and efficiently. The book begins with the Windows PowerShell basics, explores the significant features of Windows Management Framework 5.0, covers the basic concepts of Desired State Configuration and the importance of idempotent deployments. By the end of the book, you will have a good understanding of Windows PowerShell’s features and will be able to automate your tasks and manage configuration effectively.
Table of Contents (13 chapters)

Script debugging


Debugging in PowerShell is similar to that in other programming languages. Script debugging is available in the console host as well as in the PowerShell ISE; ISE has both GUI and cmdlet-based debugging, whereas console has only cmdlets to debug your scripts.

The debugging feature in the PowerShell ISE is available under the Debug tab, which is self-explanatory. Let's take a look at the breakpoints and debug cmdlets:

(Get-Command -Name *Debug*).Where({$_.Source -ne 'Azure' -and $_.CommandType -eq 'cmdlet'})
Get-Command -Name *BreakPoint

Note that in the first snippet, I used the where method to ignore Azure and to get only the core cmdlets; the output is illustrated in the following image:

Managing breakpoints

Windows PowerShell has three types of breakpoints. They are as follows:

Line breakpoints

In this, the script pauses when the designated line is reached during the operation of the script. For example, run the following command:

$line = Set-psbreakpoint -script C:\Temp\Scriptdemo...