Skip to content

Instantly share code, notes, and snippets.

@WilliamBerryiii
Created September 13, 2015 21:48
Show Gist options
  • Save WilliamBerryiii/7dc2c9004647c4e486a4 to your computer and use it in GitHub Desktop.
Save WilliamBerryiii/7dc2c9004647c4e486a4 to your computer and use it in GitHub Desktop.
Powershell v3.0+ to get all nodes configured in Scriptrock
$target = "https://my.scriptrock.applicance.com/"
$apiKey = "api_key"
$secretKey = "secret_key"
$token = $apiKey + $secretKey
$authToken = 'Token token="' + $token + '"'
$headers = @{'Authorization'=$authToken;'Content-Type'='application/json'; 'Accept'='application/json'}
$page = 0
$perPage = 10
$nodes = @()
while($true){
$page += 1
$resource = 'api/v1/nodes.json'
$pager = "?page=$page&per_page=$perPage"
$url = $target + $resource + $pager
try{
$responseNodes = Invoke-RestMethod -Method Get -Uri $url -Headers $headers -TimeoutSec 300
if($responseNodes.Count -eq 0 ) { break }
}
catch [Exception]
{
write-host $_.Exception|format-list -force
}
$nodes += $responseNodes
}
write-host ($nodes | out-string)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment