FunctionsPublic/Add-GraphPageToSite.ps1

<#
.SYNOPSIS
Add a SharePoint page to a SharePoint site
 
.DESCRIPTION
Adds a SharePoint page to the specified Sharepoint site. Uses the beta API.
 
.PARAMETER accessToken
A Microsoft Graph API access token with the required permissions
 
.PARAMETER sharePointSiteID
The SharePoint site to which the page should be added
 
.PARAMETER pageObject
JSON object in string format that defines the sitePage content.
#>

function Add-GraphPageToSite
{
    param(
        [parameter(Mandatory=$true)][psobject]$accessToken, 
        [parameter(Mandatory=$true)][string]$sharePointSiteID, 
        [parameter(Mandatory=$true)][string]$pageObject
    )

    $responseBody = Invoke-RestMethod `
        -Uri "https://graph.microsoft.com/beta/sites/$($sharePointSiteID)/pages" `
        -Headers @{"Authorization" = "Bearer $($accessToken.AccessTokenCredential.GetNetworkCredential().password)"} `
        -Body $pageObject `
        -ContentType "application/json" `
        -Method POST
    
    if($null -eq $responseBody)
    {
        return $null
    }
    else
    {
        return $responseBody.value
    }
}