Last active
May 21, 2019 18:35
-
-
Save vgrem/fe0cda40b5ed0cd9070c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.\Get-SPOAccessToken.ps1 | |
<# | |
.Synopsis | |
Sends an HTTP or HTTPS request to a SharePoint Online REST-compliant web service. | |
.DESCRIPTION | |
This function sends an HTTP or HTTPS request to a Representational State | |
Transfer (REST)-compliant ("RESTful") SharePoint Online web service. | |
.EXAMPLE | |
Invoke-SPORestMethod -Uri "https://contoso.sharepoint.com/_api/web" -AccessToken $accessToken | |
#> | |
Function Invoke-SPORestMethod() | |
{ | |
Param( | |
[Uri]$Uri, | |
[Object]$Body, | |
[Hashtable]$Headers, | |
[Microsoft.PowerShell.Commands.WebRequestMethod]$Method = [Microsoft.PowerShell.Commands.WebRequestMethod]::Get, | |
[string]$AccessToken | |
) | |
$contentType = 'application/json;odata=verbose' | |
if(-not $Headers) { | |
$Headers = @{} | |
} | |
$Headers["Accept"] = "application/json;odata=verbose" | |
$Headers.Add('Authorization','Bearer ' + $AccessToken) | |
Invoke-RestMethod -Method $Method -Uri $Uri -ContentType $contentType -Headers $Headers -Body $Body | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment