Book Image

Windows PowerShell for .NET Developers - Second Edition

Book Image

Windows PowerShell for .NET Developers - 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)

Imperative versus declarative programming


Imperative programming means describing the computations in terms of statements, as we do in procedural programming. In imperative programming, we instruct the computer on which operation to do and how to do it. It is an explicit sort of coding. For example, we use imperative programming to perform certain operations and catch all the exceptions that may occur, or to install software if it does not exist on a specific machine. PowerShell uses imperative programming style, except in the DSC feature. In the preceding topic, we installed the PowerShell ISE using the ServerManager module, which is an imperative programming practice. Let's revisit it—what we will do here is check whether the PowerShell ISE feature is installed; if not, we will proceed with the installation.

We removed the PowerShell ISE using the Remove-WindowsFeature cmdlet. Now, we will execute the following code to install the PowerShell ISE:

Import-Module ServerManager
If (-not (Get...