Pre-Processor Script (File Importer Only)
A custom script that can be run on the files that are about to be read in by the File Importer. This allows for pre-data clean-up and validation.
Post Processor Script (All Importers)
A custom script that can be run on the data retrieved from the File, SQL, or REST API source, but before it is passed through to the importer.
Pre / Post Processor Script
$ScriptArgs.EventArg1: Name of the import block that called this code.
e.g. Import1-PreProcess, Import1-PostProcess, Import2-PreProcess, Import2-PostProcess etc
$blockName = $ScriptArgs.EventArg1
$ScriptArgs.EventArg2: A comma-delimited list of files to process
$files = $ScriptArgs.EventArg2.Split(",",[System.StringSplitOptions]::RemoveEmptyEntries)
Returning an Error will end the current import block, but
New-MSApiResult -Header "No files found to process" -Status Error
Returning an Exception will end the current import block and end all subsequent import blocks
New-MSApiResult -Header "No files found to process" -Status Exception
Example Script
## Importer Processing Scripts # EventArg1: Name of the import block that called this code. # e.g. Import1-PreProcess $blockName = $ScriptArgs.EventArg1 # EventArg2: A comma-delimited list of files to process $files = $ScriptArgs.EventArg2.Split(",",[System.StringSplitOptions]::RemoveEmptyEntries) ## Example 1. Exit importer if there are no files to import if($files.count -eq 0) { New-MSApiResult -Header "No files found to process" -Status Exception return } ## Example 2. Skip import if the number of rows to import < 3 foreach($file in $files) { $lineCount = (Get-Content $file | Measure-Object -Line).Lines if($lineCount -lt 3){ New-MSApiResult -Header "Bad import file, not enough data rows" -Status Error } }
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article