Book Image

Windows PowerShell for .NET Developers - Second Edition

By : Chendrayan Venkatesan, Sherif Talaat
Book Image

Windows PowerShell for .NET Developers - Second Edition

By: Chendrayan Venkatesan, Sherif Talaat

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)

Exploring API using PowerShell

We considered a basic example of using the Windows API. There are different ways to use APIs in PowerShell based on the requirements. Windows PowerShell has the feature of interacting with .NET DLL files as well. Let's consider that you have a code that simply performs addition operations that we can load in PowerShell and then explores the methods. But why are we discussing DLL now? Here is a comparison of API and DLL:





In this, the interface is implemented by the software program

This is a method of providing APIs

An API is an interface to the library of code

DLL is nothing but a library of code

In short, DLL is a file format and a way to use API.

Let's take a look at a demo where we will use a custom DLL file in Windows PowerShell. For this, we will choose a class library in Visual C# and build a code that will simply add two given integers.

The C# code is as follows:

using System;
using System.Collections.Generic;
using System...