fix: restore .value access when using -AllPages on group queries
Invoke-GraphRequest with -AllPages returns the full response object with accumulated items in .value, not a flat array.
This commit is contained in:
@@ -279,7 +279,7 @@ if($Mode -eq "Backup")
|
|||||||
Write-Host "`nLoading groups for backup resolution..." -ForegroundColor Cyan
|
Write-Host "`nLoading groups for backup resolution..." -ForegroundColor Cyan
|
||||||
$backupGroupsResponse = Invoke-GraphRequest "/groups?`$select=id,displayName&`$orderby=displayName" -AllPages
|
$backupGroupsResponse = Invoke-GraphRequest "/groups?`$select=id,displayName&`$orderby=displayName" -AllPages
|
||||||
$backupGroups = @{}
|
$backupGroups = @{}
|
||||||
foreach($g in $backupGroupsResponse)
|
foreach($g in $backupGroupsResponse.value)
|
||||||
{
|
{
|
||||||
$backupGroups[$g.id] = $g.displayName
|
$backupGroups[$g.id] = $g.displayName
|
||||||
}
|
}
|
||||||
@@ -383,7 +383,7 @@ elseif($Mode -eq "Restore")
|
|||||||
# Resolve group names to IDs in current tenant if needed
|
# Resolve group names to IDs in current tenant if needed
|
||||||
Write-Host "`nLoading current tenant groups for name resolution..." -ForegroundColor Cyan
|
Write-Host "`nLoading current tenant groups for name resolution..." -ForegroundColor Cyan
|
||||||
$currentGroupsResponse = Invoke-GraphRequest "/groups?`$select=id,displayName&`$orderby=displayName" -AllPages
|
$currentGroupsResponse = Invoke-GraphRequest "/groups?`$select=id,displayName&`$orderby=displayName" -AllPages
|
||||||
$currentGroups = $currentGroupsResponse
|
$currentGroups = $currentGroupsResponse.value
|
||||||
|
|
||||||
$success = 0
|
$success = 0
|
||||||
$skipped = 0
|
$skipped = 0
|
||||||
|
|||||||
@@ -253,7 +253,7 @@ Write-Host "Selected $($selectedApps.Count) apps." -ForegroundColor Green
|
|||||||
#region Load Groups
|
#region Load Groups
|
||||||
Write-Host "`nLoading Azure AD groups..." -ForegroundColor Cyan
|
Write-Host "`nLoading Azure AD groups..." -ForegroundColor Cyan
|
||||||
$groupsResponse = Invoke-GraphRequest "/groups?`$select=id,displayName&`$orderby=displayName" -AllPages
|
$groupsResponse = Invoke-GraphRequest "/groups?`$select=id,displayName&`$orderby=displayName" -AllPages
|
||||||
$groups = $groupsResponse | Where-Object { $_.displayName } | Sort-Object displayName
|
$groups = $groupsResponse.value | Where-Object { $_.displayName } | Sort-Object displayName
|
||||||
Write-Host "Found $($groups.Count) groups." -ForegroundColor Green
|
Write-Host "Found $($groups.Count) groups." -ForegroundColor Green
|
||||||
|
|
||||||
$groupDisplayNames = $groups | ForEach-Object { "$($_.displayName) [$($_.id)]" }
|
$groupDisplayNames = $groups | ForEach-Object { "$($_.displayName) [$($_.id)]" }
|
||||||
|
|||||||
@@ -296,7 +296,7 @@ Write-Host "Selected $($selectedObjects.Count) objects." -ForegroundColor Green
|
|||||||
#region Load groups & filters
|
#region Load groups & filters
|
||||||
Write-Host "`nLoading Azure AD groups..." -ForegroundColor Cyan
|
Write-Host "`nLoading Azure AD groups..." -ForegroundColor Cyan
|
||||||
$groupsResponse = Invoke-GraphRequest "/groups?`$select=id,displayName&`$orderby=displayName" -AllPages
|
$groupsResponse = Invoke-GraphRequest "/groups?`$select=id,displayName&`$orderby=displayName" -AllPages
|
||||||
$groups = $groupsResponse | Where-Object { $_.displayName } | Sort-Object displayName
|
$groups = $groupsResponse.value | Where-Object { $_.displayName } | Sort-Object displayName
|
||||||
Write-Host "Found $($groups.Count) groups." -ForegroundColor Green
|
Write-Host "Found $($groups.Count) groups." -ForegroundColor Green
|
||||||
|
|
||||||
Write-Host "`nLoading assignment filters..." -ForegroundColor Cyan
|
Write-Host "`nLoading assignment filters..." -ForegroundColor Cyan
|
||||||
|
|||||||
@@ -379,7 +379,7 @@ if($baseline.ContainsKey("groups") -and $baseline["groups"])
|
|||||||
{
|
{
|
||||||
Write-Host "`nResolving groups..." -ForegroundColor Cyan
|
Write-Host "`nResolving groups..." -ForegroundColor Cyan
|
||||||
$existingGroupsResp = Invoke-GraphRequest "/groups?`$select=id,displayName&`$orderby=displayName" -AllPages
|
$existingGroupsResp = Invoke-GraphRequest "/groups?`$select=id,displayName&`$orderby=displayName" -AllPages
|
||||||
$existingGroups = $existingGroupsResp
|
$existingGroups = $existingGroupsResp.value
|
||||||
|
|
||||||
foreach($grpDef in $baseline["groups"])
|
foreach($grpDef in $baseline["groups"])
|
||||||
{
|
{
|
||||||
@@ -414,7 +414,7 @@ if($baseline.ContainsKey("groups") -and $baseline["groups"])
|
|||||||
#region Pre-load all existing groups for assignment resolution
|
#region Pre-load all existing groups for assignment resolution
|
||||||
Write-Host "`nPre-loading group directory..." -ForegroundColor Cyan
|
Write-Host "`nPre-loading group directory..." -ForegroundColor Cyan
|
||||||
$allGroupsResp = Invoke-GraphRequest "/groups?`$select=id,displayName&`$orderby=displayName" -AllPages
|
$allGroupsResp = Invoke-GraphRequest "/groups?`$select=id,displayName&`$orderby=displayName" -AllPages
|
||||||
foreach($g in $allGroupsResp)
|
foreach($g in $allGroupsResp.value)
|
||||||
{
|
{
|
||||||
if(-not $groupCache.ContainsKey($g.displayName))
|
if(-not $groupCache.ContainsKey($g.displayName))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -243,7 +243,7 @@ if(-not $selectedTypeTitles)
|
|||||||
|
|
||||||
Write-Host "`nLoading groups for name resolution..." -ForegroundColor Cyan
|
Write-Host "`nLoading groups for name resolution..." -ForegroundColor Cyan
|
||||||
$groupsResponse = Invoke-GraphRequest "/groups?`$select=id,displayName&`$orderby=displayName" -AllPages
|
$groupsResponse = Invoke-GraphRequest "/groups?`$select=id,displayName&`$orderby=displayName" -AllPages
|
||||||
$groups = $groupsResponse
|
$groups = $groupsResponse.value
|
||||||
|
|
||||||
$reportRows = @()
|
$reportRows = @()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user