FunctionsPublic/Get-GraphItemsInLibrary.ps1

function Get-GraphItemsInLibrary
{
    param([psobject]$accessToken, [string]$documentLibraryID)
    
    if($null -eq $nextLink)
    {
        $responseBody = Invoke-RestMethod -Uri "https://graph.microsoft.com/v1.0/drives/$($documentLibraryID)/items/root/children" -Headers @{"Authorization" = "Bearer $($accessToken.AccessTokenCredential.GetNetworkCredential().password)"}
    }
    else
    {    
        $responseBody = Invoke-RestMethod -Uri $nextLink -Headers @{"Authorization" = "Bearer $($accessToken.AccessTokenCredential.GetNetworkCredential().password)"}
    }
    $jsonResponse = $responseBody | ConvertTo-JSON

    $itemsInLibraryResult = ConvertFrom-Json -InputObject $jsonResponse
    $itemsInLibrary = $itemsInLibraryResult.value

    if($itemsInLibraryResult.'@odata.nextLink'.Length -gt 0)
    {
        $itemsInLibrary += Get-GraphAllGroups -accessToken $accessToken -nextLink $itemsInLibraryResult.'@odata.nextLink'
    }

    return $itemsInLibrary
}