Created
December 14, 2016 18:57
-
-
Save jheiselman/df983ea5f9f34ea59b3e370333b6655c to your computer and use it in GitHub Desktop.
Example of how to use JSON in PowerShell
This file contains hidden or 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
| if ($username -eq "" -or $api_key -eq "" -or $serverId -eq "") { | |
| echo "Please edit this script and fill in the variables at the top before using it" | |
| exit | |
| } | |
| $auth_body = @{ | |
| auth = @{ | |
| "RAX-KSKEY:apiKeyCredentials" = @{ | |
| username = "" | |
| apiKey = "" | |
| } | |
| } | |
| } | |
| $auth_uri = "https://identity.api.rackspacecloud.com/v2.0/tokens" | |
| $auth_body.auth.'RAX-KSKEY:apiKeyCredentials'.username = $username | |
| $auth_body.auth.'RAX-KSKEY:apiKeyCredentials'.apiKey = $api_key | |
| $authentication_response = Invoke-RestMethod -Uri $auth_uri -Method Post -Body (ConvertTo-Json $auth_body) -Headers @{"Accept"= "application/json"; "Content-Type" = "application/json"} | |
| $tenantId = ($authentication_response.access.user.roles | Where-Object -Property name -EQ "compute:default").tenantId | |
| $console_uri = "https://ord.servers.api.rackspacecloud.com/v2/$tenantId/servers/$serverId/action" | |
| $console_body = @{ | |
| "os-getVNCConsole" = @{ | |
| type = "novnc" | |
| } | |
| } | |
| $console_response = Invoke-RestMethod -Uri $console_uri -Method Post -Headers @{"Accept" = "application/json"; "Content-Type" = "application/json"; "X-Auth-Token" = $authentication_response.access.token.id} -Body (ConvertTo-Json $console_body) | |
| echo $console_response.console.url | |
| #start $console_response.console.url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment