Application Notes
- Last Updated: May 6, 2025
- 2 minute read
- MOVEit Automation
- Version 2023.1
- Version 2023
- Documentation
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 .
Adding or changing a file using a custom script
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:
- Get a new temporary file name from
MOVEit Automation
. At this point it is just a file name in the cache that you can use, the file does not exist yet.
$NewCacheFileName = $miaclient.MINewCacheFilename() - Create a real name: the name of the file as it will appear when it is copied to the destination. The logic to create this real name will be specific for your use case, but often macros are used to create dynamic names based on a pattern. For example, this will use today's date as part of the file name.
$NewRealName = "MyNewFile-$($miaclient.MIMacro('[DD][MM]{YYYY]'))" - Create a new temporary file and add data to the file
Add-Content -Path $NewCacheFileName -Value "This is my data."At this point, you have created a temporary file in the cache with your data.
- In order to take this temporary file and move it to a destination with a real name, you must add the file to the
MOVEit Automation
processing queue.
$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.
Casting task parameters
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:
- Get the current value of the filecount parameter, convert it to a number, and increment it by one.
$filecount = [Long]($miaclient.MIGetTaskParam('FileCount')) + 1 - Save the parameter (it will save the number as a string)
$miaclient.MISetTaskParam("FileCount", $filecount)