Hi there
I’m trying to collect data output from invoke-restmethod to graph but the variable/array is always empty at end,very weird since i remeber i had the same issue before and i forgot what i did to solve it ![]()
$allteamsusingteams = @()
Define your Microsoft Graph API endpoint and access token
$graphApiEndpoint = “https://graph.microsoft.com/beta”
$accessToken = “sometoken”Make a GET request to retrieve teams data
$uri = “$graphApiEndpoint/teams”
$headers = @{
“Authorization” = “Bearer $accessToken”
“Content-Type” = “application/json”
}
$response = Invoke-RestMethod -Uri $uri -Headers $headers
$allteamsusingteams += $response.value
if ($response.‘@odata.nextLink’) {
do {
$response = (Invoke-RestMethod -Uri $response.‘@odata.nextLink’ -Headers $Headers -Method Get -ContentType “application/json”)
$allteamsusingteams += $response.value
} until (
!$response.‘@odata.nextLink’
)}
$data=@()
$allteamsusingteams|select -First 20|Foreach-Object -ThrottleLimit 20 -Parallel{
#Action that will run in Parallel. Reference the current object via $PSItem and bring in outside variables with $USING:varname
$groupinfouri = “$using:graphApiEndpoint/groups/$($psitem.id)”
$headers = @{
“Authorization” = “Bearer $using:accessToken”
“Content-Type” = “application/json”
}
#write-host $groupinfouri# this was just to verify i am getting the right url created and i do
$Response = Invoke-RestMethod -Uri $groupinfouri -Headers $headers
$allresponses += $response.value
}
the first piece collects all teams(basically to get the team/group id) that works without problems
the second part digs into each group by the id to collect extra info.
when i run that without the variable/array it output the data to screen without issues
any feedback will be welcome
thanks