Created
September 13, 2015 21:48
-
-
Save WilliamBerryiii/7dc2c9004647c4e486a4 to your computer and use it in GitHub Desktop.
Powershell v3.0+ to get all nodes configured in Scriptrock
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
$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