<# .DESCRIPTION Invokes a REST Method by including its Access Token as Bearer .PARAMETER Method The Method to use on the Request .PARAMETER AccessToken The AccessToken to inject in the Request Headers .PARAMETER EndpointUri The Endpoint Uri to make the Request upon .EXAMPLE Invoke-SecuredRestMethod -Method "GET" -AccessToken "" -EndpointUri "https://outlook.office365.com/api/v1.0/users('admin@tenant.onmicrosoft.com')/folders/inbox/messages" #> function Invoke-SecuredRestMethod() { Param( [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [String] $Method, [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [String] $AccessToken, [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [String] $EndpointUri ) $headers = @{ "Authorization" = [String]::Format("Bearer {0}", $AccessToken) } $results = Invoke-RestMethod -Uri $EndpointUri -Method $Method -Headers $headers return $results }