Consuming Web API or Web Request in Powershell 2.0 and 4.0

There two methods to consume the web API based on Power Shell version.

Power Shell 3.0  and latest:
For this version the method name “Invoke RestMethod” is used to consume the Web API
$apiKey = “SomeKey”
$Response= Invoke-RestMethod -Method Get -Uri $resource -Header @{ “X-ApiKey” = $apiKey }
you can print all the data:
Write-Ouput $Reponse
To change the method type:
use -Method Post
Power Shell 2.0 and earlier version:
$request = [System.Net.WebRequest]::Create(“$url”)
$request.ContentType=’application/json; charset=utf-8′
$request.GetResponse()


Categories: Powershell

Tags: , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: