Previous Topic

Next Topic

Book Contents

Book Index

Application Notes

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:

  1. 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()

  2. 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]'))"

  3. 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.

  4. 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:

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.