Skip to content

Invoke-MgmtGraphRequest

MgmtGraph: Invokes a custom REST API request against Microsoft Graph

#Requires -Version 5.1
#Requires -Modules Microsoft.Graph.Authentication

[CmdletBinding()]
Param (
    [Parameter(Mandatory = $true)]
    [string]$Uri,

    [Parameter(Mandatory = $true)]
    [ValidateSet('GET', 'POST', 'PUT', 'PATCH', 'DELETE')]
    [string]$Method,

    [string]$Body
)

Process {
    try {
        $params = @{
            'Uri'         = $Uri
            'Method'      = $Method
            'ErrorAction' = 'Stop'
        }
        if ($Body) { $params.Add('Body', $Body) }

        $result = Invoke-MgGraphRequest @params
        
        Write-Output $result
    }
    catch {
        throw
    }
}

Specifies the relative Microsoft Graph API URI (e.g., "/me", "/users").

Specifies the HTTP method for the request (GET, POST, PUT, PATCH, DELETE).

Optional. Specifies the JSON request body for POST, PUT, or PATCH operations.

An interactive directory of PowerShell scripts.