PowerShell Logo Small

Invoke-RestMethod



This is the built-in help made by Microsoft for the command 'Invoke-RestMethod', in PowerShell version 5 - as retrieved from Windows version 'Microsoft Windows Server 2012 R2 Standard' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Sends an HTTP or HTTPS request to a RESTful web service.

SYNTAX


Invoke-RestMethod [-Uri] <Uri> [-Body [<Object>]] [-Certificate [<X509Certificate>]] [-CertificateThumbprint [<String>]] [-ContentType [<String>]] [-Credential
[<PSCredential>]] [-DisableKeepAlive] [-Headers [<IDictionary>]] [-InFile [<String>]] [-InformationAction {SilentlyContinue | Stop | Continue | Inquire | Ignore | Suspend}]
[-InformationVariable [<System.String>]] [-MaximumRedirection [<Int32>]] [-Method {Default | Get | Head | Post | Put | Delete | Trace | Options | Merge | Patch}] [-OutFile
[<String>]] [-PassThru] [-Proxy [<Uri>]] [-ProxyCredential [<PSCredential>]] [-ProxyUseDefaultCredentials] [-SessionVariable [<String>]] [-TimeoutSec [<Int32>]]
[-TransferEncoding {chunked | compress | deflate | gzip | identity}] [-UseDefaultCredentials] [-UserAgent [<String>]] [-WebSession [<WebRequestSession>]] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


The Invoke-RestMethod cmdlet sends HTTP and HTTPS requests to Representational State Transfer (REST) web services that returns richly structured data.


Windows PowerShell formats the response based to the data type. For an RSS or ATOM feed, Windows PowerShell returns the Item or Entry XML nodes. For JavaScript Object
Notation (JSON) or XML, Windows PowerShell converts (or deserializes) the content into objects.


This cmdlet is introduced in Windows PowerShell 3.0.



<

RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/p/?linkid=293987
ConvertTo-Json
ConvertFrom-Json
Invoke-WebRequest

REMARKS

<

Examples


Example 1

PS C:\>Invoke-RestMethod -Uri http://blogs.msdn.com/powershell/rss.aspx | Format-Table -Property Title, pubDate
Title pubDate-----------
Another Holiday Gift from the PowerShell Team: PowerShell 3.0 CTP2... Thu, 22 Dec 2011 00:46:00 GMT
More Videos from the First PowerShell Deep Dive Mon, 10 Oct 2011 19:59:00 GMT
PowerShell Deep Dive Lineup Thu, 06 Oct 2011 00:42:00 GMT
Windows Management Framework 3.0 Community Technology Preview (CTP... Mon, 19 Sep 2011 23:56:26 GMT
Get-Help -Online Fails in German Tue, 23 Aug 2011 15:02:00 GMT
PowerShell Deep Dive Registration Info & Call for Session Proposals Wed, 20 Jul 2011 00:25:00 GMT
Invoke-Expression considered harmful Fri, 03 Jun 2011 15:43:00 GMT
PowerShell at TechEd 2011 Thu, 28 Apr 2011 16:58:36 GMT
PowerShell Language now licensed under the Community Promise Sat, 16 Apr 2011 00:13:00 GMT
Scaling and Queuing PowerShell Background Jobs Mon, 04 Apr 2011 20:30:58 GMT
More Deep Dive Info, Including Abstracts from the PowerShell Team Sun, 13 Mar 2011 01:35:42 GMT
A Few Deep Dive Abstracts Sat, 05 Mar 2011 00:26:00 GMT
Reminder: Register for the PowerShell Deep Dive Conference & submi... Wed, 23 Feb 2011 17:55:45 GMT



This command uses the Invoke-RestMethod cmdlet to get information from the Windows PowerShell Blog RSS feed. The command uses the Format-Table cmdlet to display the values
of the Title and pubDate properties of each blog in a table.






Example 2

PS C:\>$cred = Get-Credential

# Next, allow the use of self-signed SSL certificates.

[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }

# Create variables to store the values consumed by the Invoke-RestMethod command. The search variable contents are later embedded in the body variable.

$server = 'server.contoso.com'
$url = "https://${server}:8089/services/search/jobs/export"
$search = "search index=_internal | reverse | table index,host,source,sourcetype,_raw"

# The cmdlet handles URL encoding. The body variable describes the search criteria, specifies CSV as the output mode, and specifies a time period for returned data that
starts two days ago and ends one day ago. The body variable specifies values for parameters that apply to the particular REST API with which Invoke-RestMethod is
communicating.

$body = @{
search = $search
output_mode = "csv"
earliest_time = "-2d@d"
latest_time = "-1d@d"
}

# Now, run the Invoke-RestMethod command with all variables in place, specifying a path and file name for the resulting CSV output file.

Invoke-RestMethod -Method Post -Uri $url -Credential $cred -Body $body -OutFile output.csv
cmdlet Get-Credential at command pipeline position 1

Supply values for the following parameters:
{"preview":true,"offset":0,"result":{"sourcetype":"contoso1","count":"9624"}}

{"preview":true,"offset":1,"result":{"sourcetype":"contoso2","count":"152"}}

{"preview":true,"offset":2,"result":{"sourcetype":"contoso3","count":"88494"}}

{"preview":true,"offset":3,"result":{"sourcetype":"contoso4","count":"15277"}}



In the following example, a user runs Invoke-RestMethod to perform a POST request on an intranet website in the user’s organization.