Skip to content

Instantly share code, notes, and snippets.

@joshbtn
Last active September 4, 2015 17:04
Show Gist options
  • Save joshbtn/bbf847e1aecf885d1fae to your computer and use it in GitHub Desktop.
Save joshbtn/bbf847e1aecf885d1fae to your computer and use it in GitHub Desktop.
PowerShell helpers for Rest
#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