It shouldn’t be something new that I love to work with Graph API, so I am doing that very often.
So when getting Azure Resources via Graph API, you will immediately face the Paging topics.
You can read some Details here: Paging in Microsoft Graph REST API – TechGuy
So, nearly every Powershell Script, working with Graph API, needs Paging to get more than 100 Resources. So, I made a simple function you can use and paste into your Scripts instead of writing many lines every time.
The Code
function Get-AzureResourcePaging {
param (
$URL,
$AuthHeader
)
# List Get all Apps from Azure
$Response = Invoke-RestMethod -Method GET -Uri $URL -Headers $AuthHeader
$Resources = $Response.value
$ResponseNextLink = $Response."@odata.nextLink"
while ($ResponseNextLink -ne $null) {
$Response = (Invoke-RestMethod -Uri $ResponseNextLink -Headers $AuthHeader -Method Get)
$ResponseNextLink = $Response."@odata.nextLink"
$Resources += $Response.value
}
return $Resources
}
GitHub
The full Script with more Details can be found on my GitHub Repo; Seidlm/PowerShell-Templates: PowerShell Template – Logging Function (github.com)
Michael Seidl aka Techguy
au2mate everything
#automationmindset