FunctionsPublic/Publish-GraphPage.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<#
.SYNOPSIS
Publish a SharePoint page to a SharePoint site
 
.DESCRIPTION
Publish a specific SharePoint page. 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 sharePointPageID
The SharePoint page which to publish
#>

function Publish-GraphPage
{
    param(
        [parameter(Mandatory=$true)][psobject]$accessToken, 
        [parameter(Mandatory=$true)][string]$sharePointSiteID, 
        [parameter(Mandatory=$true)][string]$sharePointPageID
    )

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