I created an Azure function where I try to get all the AAD groupmembers. This timerjob needs to run once a day. When I do a test run I see in the logging it iterates a couple of time in the nextLink paging. But then it stuck without an error. I already increase the timeout to 10 minutes, but I still have the same problem.
When I run this script local on my machine it works fine. I expect it should iterate 127 times and get 12757 items. test run
When I go to the monitor logging I dont see the session which was stuck. monitoring logging
using namespace System.Net
# Input bindings are passed in via param block.
param($Timer)
"START"
$fileName = "Azure - ADGroupMembers.csv"
Write-Output "Connect to AAD"
Connect-AzAccount -identity
try {
#region auth
Write-Output "Get items from MS Graph"
$token = (Get-AzAccessToken -ResourceUrl "https://graph.microsoft.com/").Token
$authHeader = @{Authorization = "Bearer $token"}
# #endregion
# #region main proces
$allPages = @()
$items = (Invoke-RestMethod -Method 'Get' -Uri 'https://graph.microsoft.com/v1.0/groups?$top=999&$expand=members' -Headers $authHeader -ContentType 'Application/Json')
$allPages += $items.value
$index = 0
if ($items.'@odata.nextLink') {
do {
$index++
"Index counter: $index"
$token = (Get-AzAccessToken -ResourceUrl "https://graph.microsoft.com/").Token
$authHeader = @{Authorization = "Bearer $token"}
$items = (Invoke-RestMethod -Method 'Get' -Uri $items.'@odata.nextLink' -Headers $authHeader -ContentType 'Application/Json')
$allPages += $items.value
} until (
!$items.'@odata.nextLink'
)
}
$items = $allPages
"Count items: " + $items.Count
$filePath = "D:\home\data\$($fileName)"
Write-Host "Convert to csv to path '$($filePath)'" -ForegroundColor green
$items | Export-Csv -NoTypeInformation -Path $filePath
#endregion
}
catch {
write-output $_.Exception.Message
}
"FINISH"
I upgraded to premium plan and now it works fine. https://learn.microsoft.com/en-us/azure/azure-functions/functions-premium-plan?tabs=portal