[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $ServiceLocation = "http://localhost/api/v1" $login = @{ username = "jsmith" password = "Password1!" scope = "Internal" } # Logging in to Automate $json = $login | ConvertTo-Json $response = $null $response = Invoke-RestMethod "$ServiceLocation/users/password" -Method Post -Body $json -ContentType "application/json" $authToken = $response.token if ($authToken.length -eq 0 ) { Write-Error Authentication failed } function Stop-Rampiva-Job { param( [Parameter(Mandatory=$true)] [string] $JobId ) $submission =@{ "command"="STOP" } $json = $submission | ConvertTo-Json $result = $null $result = Invoke-RestMethod "$ServiceLocation/scheduler/jobs/$JobId/execution" -Method Put -Body $json -ContentType "application/json" -headers $headers return } # Get running Jobs $jobs= $null $jobs= Invoke-RestMethod "$ServiceLocation/scheduler/jobs" -headers $headers -Method Get -ContentType "application/json" Write-Host "Got $($jobs.Length) job(s)" Foreach ($job in $jobs) { if ($job.executionState -eq "RUNNING") { Write-Host "Job [$($job.Name)] is running, stopping" Stop-Rampiva-Job -JobId $job.Id } else { Write-Host "Job [$($job.Name)] is in state $($job.executionState), skipping" } }