Getting Node List from UpGuard using Powershell v3.0+
I’m completely perplexed by people who dislike Powershell. As someone who has built 1,000+ line Powershell deployment scripts, the scripting language can be a bit like bacon flavored chocolate; you’ll try it, some folks swear by it, but for the most part my conclusion is … “meh”. That said, Powershell as a SHELL is outstanding. Frankly it smokes any experience I’ve ever had on the Unix/Linux side of the fence and it’s got everything to do with direct access to .Net. So let’s put the scripting language aside and look at some things you can do with the shell and my new favorite tool UpGuard.
Connecting to UpGuard from Powershell and pulling down the node list is very straight forward. Though you’ll find some Powershell 2.0 examples in the API section of the UpGuard site, the following is an approach using the Powershell v3.0+ Cmdlet Invoke-RestMethod which will automatically deserialize the JSON response into objects - super cool!
The UpGuard API rightly enforces pagination, so the above script uses a while loop to pull out the nodes from each Cmdlet response and adds them to a master array, breaking when there are no further nodes in the response.