@@ -247,13 +247,8 @@ Get-PBIAuthToken -ClientId "C0E8435C-614D-49BF-A758-3EF858F8901B" -tenantId "com
247
247
248
248
$tokenCache = New-Object Microsoft.IdentityModel.Clients.ActiveDirectory.TokenCache
249
249
250
- if ($deviceCodeFlow )
250
+ if ($deviceCodeFlow -and ! [ string ]::IsNullOrEmpty( $tokenCacheFile ) )
251
251
{
252
- if ([string ]::IsNullOrEmpty($tokenCacheFile ))
253
- {
254
- throw " Using -DeviceCodeFlow you must set the parameter -tokenCacheFile to persist the auth token"
255
- }
256
-
257
252
if (Test-Path $tokenCacheFile )
258
253
{
259
254
$bytes = [System.IO.File ]::ReadAllBytes($tokenCacheFile )
@@ -2376,7 +2371,8 @@ Function Invoke-PBIRequest{
2376
2371
[Parameter (Mandatory = $false )] [string ] $groupId ,
2377
2372
[Parameter (Mandatory = $false )] [switch ] $ignoreGroup = $false ,
2378
2373
[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
2380
2376
2381
2377
)
2382
2378
@@ -2416,36 +2412,68 @@ Function Invoke-PBIRequest{
2416
2412
{
2417
2413
$url += " ?$odataParams "
2418
2414
}
2415
+
2416
+ $url = [SYstem.Uri ]$url
2419
2417
2420
2418
try
2421
2419
{
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 = @ ()
2426
2424
2427
- if ( $result -ne $null )
2425
+ do
2428
2426
{
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 )
2437
2462
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
2441
2466
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
+ }
2449
2477
2450
2478
if ($output )
2451
2479
{
0 commit comments