[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 Set-Rampiva-Job-Priority { param( [Parameter(Mandatory=$true)] [string] $JobId, [Parameter(Mandatory=$true)] [string] $Priority ) $submission =@{ "priority"=$Priority } $json = $submission | ConvertTo-Json $result = $null $result = Invoke-RestMethod "$ServiceLocation/scheduler/jobs/$JobId/settings" -Method Put -Body $json -ContentType "application/json" -headers $headers return $result.settings.priority } # Get Jobs $filter = "from Powershell" $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.Name.contains($filter)) { Write-Host "Job [$($job.Name)] matches filter" if ($job.executionState -eq "NOT_STARTED") { Write-Host "Job [$($job.Name)] is not running, changing priority" $newJobPriority = Set-Rampiva-Job-Priority -JobId $job.id -Priority "HIGH" Write-Host "Job [$($job.Name)] new priority: $newJobPriority" } else { Write-Host "Job [$($job.Name)] is in state $($job.executionState), skipping" } } else { Write-Host "Job [$($job.Name)] does not match filter $filter, skipping" } }