Skip to content

Commit fd59488

Browse files
author
rromano
committed
batchcount on Invoke-PBIRequest
1 parent ecae602 commit fd59488

File tree

2 files changed

+59
-31
lines changed

2 files changed

+59
-31
lines changed

Modules/PowerBIPS/PowerBIPS.psd1

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
RootModule = 'PowerBIPS.psm1'
55

66
# Version number of this module.
7-
ModuleVersion = '2.0.4.9'
7+
ModuleVersion = '2.0.4.11'
88

99
# ID used to uniquely identify this module
1010
GUID = '163A1640-A4F2-4B1F-A3AF-2796AD56200B'

Modules/PowerBIPS/PowerBIPS.psm1

+58-30
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,8 @@ Get-PBIAuthToken -ClientId "C0E8435C-614D-49BF-A758-3EF858F8901B" -tenantId "com
247247

248248
$tokenCache = New-Object Microsoft.IdentityModel.Clients.ActiveDirectory.TokenCache
249249

250-
if ($deviceCodeFlow)
250+
if ($deviceCodeFlow -and ![string]::IsNullOrEmpty($tokenCacheFile))
251251
{
252-
if ([string]::IsNullOrEmpty($tokenCacheFile))
253-
{
254-
throw "Using -DeviceCodeFlow you must set the parameter -tokenCacheFile to persist the auth token"
255-
}
256-
257252
if (Test-Path $tokenCacheFile)
258253
{
259254
$bytes = [System.IO.File]::ReadAllBytes($tokenCacheFile)
@@ -2376,7 +2371,8 @@ Function Invoke-PBIRequest{
23762371
[Parameter(Mandatory=$false)] [string] $groupId,
23772372
[Parameter(Mandatory=$false)] [switch] $ignoreGroup = $false,
23782373
[Parameter(Mandatory=$false)] [switch] $admin = $false,
2379-
[Parameter(Mandatory=$false)] [string] $odataParams = $null
2374+
[Parameter(Mandatory=$false)] [string] $odataParams = $null,
2375+
[Parameter(Mandatory=$false)] [int] $batchCount = -1
23802376

23812377
)
23822378

@@ -2416,36 +2412,68 @@ Function Invoke-PBIRequest{
24162412
{
24172413
$url += "?$odataParams"
24182414
}
2415+
2416+
$url = [SYstem.Uri]$url
24192417

24202418
try
24212419
{
2422-
$result = Invoke-RestMethod -Uri $url -Headers $headers -Method $method -Body $body -ContentType $contentType `
2423-
-TimeoutSec $timeoutSec -OutFile $outFile
2424-
2425-
$output = $result
2420+
# If batchcount is specified use the Skip & batch parameter to iterate all the results
2421+
2422+
$skip = 0
2423+
$result = @()
24262424

2427-
if ($result -ne $null)
2425+
do
24282426
{
2429-
if ($result.PSObject.Properties['value'])
2430-
{
2431-
$output = $result.value
2432-
}
2433-
2434-
if ($resource -eq "activityevents" -and $result)
2435-
{
2436-
$output = @($result.activityEventEntities)
2427+
$requestUrl = $url.ToString()
2428+
2429+
if ($batchCount -gt 0)
2430+
{
2431+
if ($url.Query)
2432+
{
2433+
$requestUrl += "&"
2434+
}
2435+
else
2436+
{
2437+
$requestUrl += "?"
2438+
}
2439+
2440+
$requestUrl += "`$top=$batchCount&`$skip=$skip"
2441+
}
2442+
2443+
$batch = Invoke-RestMethod -Uri $requestUrl -Headers $headers -Method $method -Body $body -ContentType $contentType -TimeoutSec $timeoutSec -OutFile $outFile
2444+
2445+
if ($batch -ne $null -and $batch.PSObject.Properties['value'])
2446+
{
2447+
$batch = $batch.value
2448+
}
2449+
2450+
if ($batch)
2451+
{
2452+
$result += $batch
2453+
2454+
$skip = $skip + $batchCount
2455+
}
2456+
}
2457+
while($batchCount -gt 0 -and $batch.Count -ne 0 -and $batch.Count -ge $batchCount)
2458+
2459+
if ($resource -eq "activityevents" -and $result)
2460+
{
2461+
$output = @($result.activityEventEntities)
24372462

2438-
while($result.continuationToken -ne $null)
2439-
{
2440-
$result = Invoke-RestMethod -Uri $result.continuationUri -Headers $headers -Method $method -ContentType $contentType -TimeoutSec $timeoutSec
2463+
while($result.continuationToken -ne $null)
2464+
{
2465+
$result = Invoke-RestMethod -Uri $result.continuationUri -Headers $headers -Method $method -ContentType $contentType -TimeoutSec $timeoutSec
24412466

2442-
if ($result.activityEventEntities)
2443-
{
2444-
$output += $result.activityEventEntities
2445-
}
2446-
}
2447-
}
2448-
}
2467+
if ($result.activityEventEntities)
2468+
{
2469+
$output += $result.activityEventEntities
2470+
}
2471+
}
2472+
}
2473+
else
2474+
{
2475+
$output = $result
2476+
}
24492477

24502478
if ($output)
24512479
{

0 commit comments

Comments
 (0)