Last active
September 4, 2015 17:04
-
-
Save joshbtn/bbf847e1aecf885d1fae to your computer and use it in GitHub Desktop.
PowerShell helpers for Rest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Get all results when rest endpoints paginate. | |
function Get-All-RestMethod ($CurrentObj, [int] $Skip, [string] $Uri, [hashtable] $Headers){ | |
$results = Invoke-RestMethod -Uri "$Uri`?skip=$skip" -Headers $Headers | |
$ItemsPerPage = [int]$results.ItemsPerPage | |
$TotalResults = [int]$results.TotalResults | |
$NextSkip = $skip + $ItemsPerPage | |
if( ($TotalResults - $NextSkip) -gt 0 ){ | |
$results = Get-All-RestMethod $results $NextSkip "$Uri" $Headers | |
} | |
if(!$CurrentObj){ | |
return $results | |
} | |
return $results,$CurrentObj | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment