To best utilize the custom scripts functionality, you must be familiar with how MOVEit Automation processes files in tasks. For more information, see Key Processing Concepts.
The following are examples of how to use custom scripting to add, change, or edit files during processing in MOVEit Automation.
A common pattern in advanced scripting is to create or modify a file as a task runs, and move that file to the destination just like any file that was downloaded from a source.
To add a file as a task is processing using a custom script:
$NewCacheFileName = $miaclient.MINewCacheFilename()
$NewRealName = "MyNewFile-$($miaclient.MIMacro('[DD][MM]{YYYY]'))"
Add-Content -Path $NewCacheFileName -Value "This is my data."
At this point, you have created a temporary file in the cache with your data.
$miaclient.MIAddFile($NewCacheFileName, $NewRealName)
The new file will be queued up to send to your destination. It is named using the value in $NewRealName
. The temporary file that was created in the cache will be automatically deleted after the file has been moved to the destination.
By using GetTaskParam()
and SetTaskParam()
, you can save values between invocations of the script within a single run of a task.
However, if you are attempting to save and retrieve numeric values, and perform any math on them, such as incrementing a counter, you need to ‘cast’ the value before you can use it in a math operation. This is because Task and Global parameters are saved and retrieved as strings.
For example, if you have a task parameter named filecount where you store a count of files processed by your script, you need to add something like the following to your script:
$filecount = [Long]($miaclient.MIGetTaskParam('FileCount')) + 1
$miaclient.MISetTaskParam("FlleCount", $filecount)
Note: You can only access your parameters during a task run. While the parameters will retain their values across many runs of a script within a single task, they will not maintain their values between task runs. However, you can, as part of a task run, chain two or more tasks together, and pass the parameters from one task to the next.