Please note that you must upgrade to MOVEit Automation 2018 and have the API licensed to enjoy the benefits of the REST API.
What is a REST API?
In essence, once the client has a URL from its initial connection, it can continue to use that URL in subsequent requests (in a similar way to how COM objects can be reused). Each call must be authorised with the simple passing of a token.
Getting started
$URI = “https://localhost/webadmin/api/v1”
Note that if using localhost, you will have a certificate error. To avoid this, insert the following line of code into the top of your script:
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }
Each group of functions adds a new path to the URL, with individual functions grouped beneath the branch. To list the defined hosts, for example, you would use the following:
$hosts = “$URI/hosts”
To start a task you would use:
$start = “$URI/tasks/$taskID/start”
The available paths containing the functions are:
- Config (Extract, import)
- Hosts (List, Get, but apparently not add or modify!)
- Reports (Generate File, Task or Audit reports)
- Tasks (Add, List tasks, list running tasks, Modify, Delete, Start Task, Start Scheduler, Stop Task, Stop Scheduler)
Here is a ‘bare bones’ script that stops the scheduler, waits for all tasks to complete, then stops the automation service itself. This is perfect for automating server reboots. This script does not contain error handling, nor is there a limit on how long to wait before giving up on stopping tasks:
$PWD = “Mypass”
$URI = “https://myservername.com/webadmin/api/v1”
$token = “$URI/token”
$list = “$URI/tasks/running”
$stop = “$URI/tasks/scheduler/stop”
$authstring = “grant_type=password&username=$UID&password=$PWD”
$auth = Invoke-RestMethod -Uri $token -Method Post -Body $authstring
$mytoken = $auth.access_token
$headers = @{“Authorization” = “Bearer $mytoken”}
“Stopping Scheduler”
Invoke-RestMethod -Uri $stop -Method Put -Headers $headers
“Checking for running Tasks”
$count = 1
while ($count -gt 0) {
$tasks = Invoke-RestMethod -Uri $list -Method Get -Headers $headers
$count = $tasks.items.length
if ($count -gt 0) {
“$count tasks running, sleeping 10 seconds”
sleep 10
}
}
stop-Service Moveitcentral
Did you find this useful?
Receive tips and news in your inbox

