Skip to content

Commit 1006c6a

Browse files
authored
Merge pull request #411 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 4b7b729 + a0ef206 commit 1006c6a

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ListGraphRequest.ps1

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,15 @@ function Invoke-ListGraphRequest {
120120

121121
try {
122122
$Results = Get-GraphRequestList @GraphRequestParams
123-
if ($Results.nextLink) {
124-
Write-Host "NextLink: $($Results.nextLink | Select-Object -Last 1)"
123+
if ($Results | Where-Object { $_.nextLink }) {
124+
Write-Host "NextLink: $($Results.nextLink | Where-Object { $_ } | Select-Object -Last 1)"
125125
if ($Request.Query.TenantFilter -ne 'AllTenants') {
126-
$Metadata['nextLink'] = $Results.nextLink | Select-Object -Last 1
126+
$Metadata['nextLink'] = $Results.nextLink | Where-Object { $_ } | Select-Object -Last 1
127+
}
128+
# Remove nextLink trailing object only if it’s the last item
129+
if ($Results[-1].PSObject.Properties.Name -contains 'nextLink') {
130+
$Results = $Results | Select-Object -First ($Results.Count - 1)
127131
}
128-
#Results is an array of objects, so we need to remove the last object before returning
129-
$Results = $Results | Select-Object -First ($Results.Count - 1)
130132
}
131133
if ($Request.Query.ListProperties) {
132134
$Columns = ($Results | Select-Object -First 1).PSObject.Properties.Name

0 commit comments

Comments
 (0)