Skip to content

Instantly share code, notes, and snippets.

@srpomeroy
Created October 29, 2016 00:30
Show Gist options
  • Save srpomeroy/96b3783e133e5f09f7e8286505594385 to your computer and use it in GitHub Desktop.
Save srpomeroy/96b3783e133e5f09f7e8286505594385 to your computer and use it in GitHub Desktop.
Examples on how to use PowerShell with RightScale API
# Provide API Refresh Token - http://docs.rightscale.com/cm/dashboard/settings/account/enable_oauth.html
$oauthRefreshToken = "<API_REFRESH_TOKEN>"
## Get a bearer access token from Cloud Management
$oauthUrl = "https://my.rightscale.com/api/oauth2"
$oauthHeaders = @{"X_API_VERSION"="1.5"}
$oauthBody = @{"grant_type"="refresh_token";"refresh_token"=$oauthRefreshToken}
$oauthResult = Invoke-RestMethod -Method Post -Uri $oauthUrl -Headers $oauthHeaders -Body ($oauthBody | ConvertTo-Json) -ContentType "application/json"
$accessToken = $oauthResult.access_token
## PowerShell Example of Docs cURL Example @ http://docs.rightscale.com/api/api_1.5_examples/tags.html
$uri = "https://my.rightscale.com/api/tags/by_tag"
$headers = @{
"X_API_VERSION"="1.5";
"Authorization"="Bearer $accessToken"
}
$body = @{
resource_type = 'instances';
tags = @(
'database:active=true';
'rs_monitoring:state=active'
)
match_all='true'
}
$result = Invoke-RestMethod -Method POST -Uri $uri -Headers $headers -Body ($body | ConvertTo-Json) -ContentType "application/json"
# Display the matching instance hrefs
$result.links.href
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment