Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sauceaaron/4049307d5aa09c2834c2f41ebd472cec to your computer and use it in GitHub Desktop.
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
$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