Added batch mode

Added logic to allow the script to be run as part of a Batch action.