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 web requests

Web requests help us request data from Uniform Resource Identifier (URI). A developer performs many tasks using a web request, such as finding a response, downloading files, and reading files from the Internet.

In this topic, we will take a look at the cmdlets used for web requests and the WebRequest class.

Using the Windows PowerShell cmdlet, Invoke-WebRequest, we can perform a few tasks. Run the following command:

#Read the help document
help Invoke-WebRequest –Detailed

This gives the help content.

#Using the command
$site = Invoke-WebRequest
$site | GM

This lists the members (Methods and Properties)

#Checking the Status Code
"The Site Status Code is `t" + $site.StatusCode
"Description`t" + $site.StatusDescription

The preceding command outputs the status code and description, as shown in the following image:

Now, run the following command:

Invoke-WebRequest -Uri

The Invoke-WebRequest cmdlet sends http(s), FTP, and file requests...