Created
August 18, 2017 23:19
-
-
Save sauceaaron/4049307d5aa09c2834c2f41ebd472cec to your computer and use it in GitHub Desktop.
Use Powershell to call the Sauce REST API to shutdown Sauce Connect tunnels using Credentials Windows Dialog
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
| $credentials = Get-Credential | |
| $sauceRestUrl = "https://saucelabs.com/rest/v1" | |
| $userEndpoint = "$sauceRestUrl/users/$username" | |
| $tunnelsEndpoint = "$sauceRestUrl/$username/tunnels" | |
| $user = Invoke-WebRequest -Uri $userEndpoint -Credential $credentials | ConvertFrom-Json | |
| $tunnels = Invoke-WebRequest -Uri $tunnelsEndpoint -Credential $credentials | ConvertFrom-Json | |
| ForEach ($tunnelId in $tunnels) | |
| { | |
| $tunnel Invoke-WebRequest -Headers $headers -Uri $tunnelsEndpoint/$tunnelId | ConvertFrom-Json | |
| If ($tunnel.status -eq 'running') | |
| { | |
| echo "shutting down $($tunnel.id) $($tunnel.tunnel_identifier)" | |
| Invoke-WebRequest -Method Delete -Headers $headers -Uri $tunnelsEndpoint/$tunnelId | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment