Skip to content

Commit d029fa4

Browse files
committed
fix bulk requests
1 parent 9d95cad commit d029fa4

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Users/Invoke-ListUserMailboxDetails.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using namespace System.Net
22

3-
Function Invoke-ListUserMailboxDetails {
3+
function Invoke-ListUserMailboxDetails {
44
<#
55
.FUNCTIONALITY
66
Entrypoint
@@ -67,6 +67,7 @@ Function Invoke-ListUserMailboxDetails {
6767
$usernames = New-GraphGetRequest -tenantid $TenantFilter -uri 'https://graph.microsoft.com/beta/users?$select=id,userPrincipalName&$top=999'
6868
$Results = New-ExoBulkRequest -TenantId $TenantFilter -CmdletArray $Requests -returnWithCommand $true -Anchor $username
6969
Write-Host "First line of usernames is $($usernames[0] | ConvertTo-Json)"
70+
7071
# Assign variables from $Results
7172
$MailboxDetailedRequest = $Results.'Get-Mailbox'
7273
$PermsRequest = $Results.'Get-MailboxPermission'
@@ -75,7 +76,8 @@ Function Invoke-ListUserMailboxDetails {
7576
$ArchiveSizeRequest = $Results.'Get-MailboxStatistics'
7677
$BlockedSender = $Results.'Get-BlockedSenderAddress'
7778
$PermsRequest2 = $Results.'Get-RecipientPermission'
78-
$StatsRequest = New-GraphGetRequest -uri "https://outlook.office365.com/adminapi/beta/$($TenantFilter)/Mailbox('$($MailboxDetailedRequest.UserPrincipalName)')/Exchange.GetMailboxStatistics()" -Tenantid $TenantFilter -scope ExchangeOnline -noPagination $true
79+
80+
$StatsRequest = New-GraphGetRequest -uri "https://outlook.office365.com/adminapi/beta/$($TenantFilter)/Mailbox('$($UserID)')/Exchange.GetMailboxStatistics()" -Tenantid $TenantFilter -scope ExchangeOnline -noPagination $true
7981

8082

8183
# Handle ArchiveEnabled and AutoExpandingArchiveEnabled

Modules/CIPPCore/Public/GraphHelper/New-ExoBulkRequest.ps1

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function New-ExoBulkRequest {
8585
}
8686
$BatchBodyJson = ConvertTo-Json -InputObject $BatchBodyObj -Depth 10
8787
$Results = Invoke-RestMethod $BatchURL -ResponseHeadersVariable responseHeaders -Method POST -Body $BatchBodyJson -Headers $Headers -ContentType 'application/json; charset=utf-8'
88-
$ReturnedData.Add($Results.responses)
88+
$ReturnedData.AddRange(@($Results.responses))
8989

9090
Write-Host "Batch #$($batches.IndexOf($batch) + 1) of $($batches.Count) processed"
9191
}
@@ -101,7 +101,7 @@ function New-ExoBulkRequest {
101101
foreach ($item in $ReturnedData) {
102102
$itemId = $item.id
103103
$CmdletName = $IdToCmdletName[$itemId]
104-
$body = $item.body
104+
$body = $item.body.PSObject.Copy()
105105

106106
if ($body.'@adminapi.warnings') {
107107
Write-Warning ($body.'@adminapi.warnings' | Out-String)
@@ -116,16 +116,16 @@ function New-ExoBulkRequest {
116116
}
117117
$resultValue = $body.value
118118

119-
# Assign results without using += or ArrayList
120119
if (-not $FinalData.ContainsKey($CmdletName)) {
121-
$FinalData[$CmdletName] = @($resultValue)
120+
$FinalData[$CmdletName] = [System.Collections.Generic.List[object]]::new()
121+
$FinalData.$CmdletName.Add($resultValue)
122122
} else {
123-
$FinalData[$CmdletName] = $FinalData[$CmdletName] + $resultValue
123+
$FinalData.$CmdletName.Add($resultValue)
124124
}
125125
}
126126
} else {
127127
$FinalData = foreach ($item in $ReturnedData) {
128-
$body = $item.body
128+
$body = $item.body.PSObject.Copy()
129129

130130
if ($body.'@adminapi.warnings') {
131131
Write-Warning ($body.'@adminapi.warnings' | Out-String)
@@ -141,7 +141,6 @@ function New-ExoBulkRequest {
141141
$body.value
142142
}
143143
}
144-
145144
return $FinalData
146145

147146
} else {

0 commit comments

Comments
 (0)