Request an HTTP resource using the GET method in PowerShell

Posted: (EET/GMT+2)

 

PowerShell provides a large library of built-in functions, and it's no surprise that HTTP (web) methods are also included. Sometimes, you might need to execute a HTTP GET request to a particular URL address, and get the results. Luckily, the PowerShell command "Invoke-WebRequest" does just that.

Here's an example:

Invoke-WebRequest http://www.bing.com/

This returns an object with various HTTP response information. If you are just interested in the actual response body (say, a piece of HTML code), you can do this:

$html = (Invoke-WebRequest http://www.bing.com/).Content

Happy scripting!