Invoke-MgGraphRequest

Invoke-MgGraphRequest issues REST API requests to the Graph API. It works for any Graph API if you know the REST URI, method, and optional body parameter. This command is especially useful for accessing APIs for which there isn't an equivalent cmdlet yet.

Syntax

Invoke-MgGraphRequest
      [[-Method] <GraphRequestMethod>]
      [-Uri] <Uri>
      [[-Body] <Object>]
      [[-Headers] <IDictionary>]
      [[-OutputFilePath] <String>]
      [-InferOutputFileName]
      [[-InputFilePath] <String>]
      [-PassThru]
      [-SkipHeaderValidation]
      [[-ContentType] <String>]
      [[-SessionVariable] <String>]
      [[-ResponseHeadersVariable] <String>]
      [[-StatusCodeVariable] <String>]
      [-SkipHttpErrorCheck]
      [[-GraphRequestSession] <GraphRequestSession>]
      [[-UserAgent] <String>]
      [[-OutputType] <OutputType>]
      [-ProgressAction <ActionPreference>]
      [<CommonParameters>]

Description

This command issues REST API requests.

Examples

Example 1: Using Invoke-MgGraphRequest

PS C:\> Invoke-MgGraphRequest -Method GET https://graph.microsoft.com/v1.0/me
Name                           Value
----                           -----
userPrincipalName              admin@Contoso.com
preferredLanguage              en-US
mobilePhone                    425-555-0101
displayName                    MOD Administrator
givenName                      MOD
mail                           admin@contoso.com
@odata.context                 https://graph.microsoft.com/v1.0/$metadata#users/$entity
id                             694bab60-392a-4f64-9430-c1dea2951f50
jobTitle
officeLocation
businessPhones                 {425-555-0100}
surname                        Administrator

Issues REST API requests.

Parameters

-Body

Request Body. Required when Method is Post or Patch

Type:Object
Position:3
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-ContentType

Custom Content Type

Type:String
Position:11
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-GraphRequestSession

Custom Graph Request Session

Type:GraphRequestSession
Position:17
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Headers

Optional Custom Headers

Type:IDictionary
Position:4
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-InferOutputFileName

Infer output filename

Type:SwitchParameter
Position:6
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-InputFilePath

Input file to send in the request

Type:String
Position:7
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Method

HTTP Method

Type:GraphRequestMethod
Accepted values:GET, POST, PUT, PATCH, DELETE
Position:1
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-OutputFilePath

Output file where the response body will be saved

Type:String
Position:5
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-OutputType

Output Type to return to the caller

Type:OutputType
Accepted values:HashTable, PSObject, HttpResponseMessage, Json
Position:19
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-PassThru

Indicates that the cmdlet returns the results, in addition to writing them to a file. Only valid when the OutFile parameter is also used.

Type:SwitchParameter
Position:8
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-ProgressAction

{{ Fill ProgressAction Description }}

Type:ActionPreference
Aliases:proga
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-ResponseHeadersVariable

Response Headers Variable

Type:String
Aliases:RHV
Position:14
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-SessionVariable

Specifies a web request session. Enter the variable name, including the dollar sign ($).You can't use the SessionVariable and GraphRequestSession parameters in the same command.

Type:String
Aliases:SV
Position:13
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-SkipHeaderValidation

Add headers to Request Header collection without validation

Type:SwitchParameter
Position:10
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-SkipHttpErrorCheck

Skip Checking HTTP Errors

Type:SwitchParameter
Position:16
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-StatusCodeVariable

Response Status Code Variable

Type:String
Position:15
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Uri

Uri to call can be segments such as /beta/me or fully qualified https://graph.microsoft.com/beta/me

Type:Uri
Position:2
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-UserAgent

Custom User Specified User Agent

Type:String
Position:18
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

Inputs

System.Object

Outputs

System.Object