Issue with switch command

I have a script i am running below and pass in a set of arguments for example the one below but the powershell script is not picking up the distribution list and the text file for the one that matches the input strings the best. In this example its is picking up the distribution list for PRD_TEST_*START rather than PRD_TEST_BOX_BOX_BOX_REL so i am unsure why it is not picking up the closest match. Any help much appreciated,

regards

Paul

Batch_Email.ps1 CAUAJM_I_40245 EVENT: CHANGE_STATUS STATUS: SUCCESS JOB: PRD_TEST_BOX_BOX_BOX_REL

# Assign variables for parameters passed by Event Management
$STATUS = $args[4]
$JOB = $args[6]
$MACHINE = $args[8]
$RETCODE = $args[10]

# Allocate temporary work files for mail text
$TEXTFILE = "C:\Temp\email5$JOB.txt.$PID"

# Create Distribution list and Assignee Group based on jobname
switch -Wildcard ($args -join '') {        
    "MUST_START_ALARM*PRD_TEST_START_BOX_BOX_BOX_*" {
        $distrib = "TEST-Bair-TEST@BairAutosys.test.xmatters.com,TESTcommandcentre@test.com,IMSUKNTOPS_MAIL@test.com,baan_faults@test.com,pnixon@test.com"
    }
    "*PRD_TEST_START_BOX_BOX_BOX_REL*" {
        $distrib = "TESTcommandcentre@test.com,IMSUKNTOPS_MAIL@test.com,pnixon@test.com,abullen1@test.com,ccampb21@test.com,mkeefe@test.com,yali2@test.com,zpatel2@test.com"
    }
    "*PRD_TEST_START_BOX_BOX_BOX_*" {
        $distrib = "TESTcommandcentre@test.com,IMSUKNTOPS_MAIL@test.com,pnixon@test.com,abullen1@test.com,ccampb21@test.com,zpatel2@test.com,mkeefe@test.com,yali2@test.com"
    }
    "*PRD_TEST_TEST3632V_LN_REINDEXING_*_1800_BOX_SAT*" {
        $distrib = "TESTcommandcentre@test.com,IMSUKNTOPS_MAIL@test.com,pnixon@test.com,abullen1@test.com,ccampb21@test.com,zpatel2@test.com,mkeefe@test.com,yali2@test.com"
        $group = "CSC.All.Eur.MCS.PCS"
    }
    "*MAXRUNALARM*PRD_TEST_STOP_BOX_BOX_BOX*" {
        $distrib = "TEST-Bair-TEST@BairAutosys.test.xmatters.com,TESTcommandcentre@test.com,IMSUKNTOPS_MAIL@test.com,pnixon@test.com"
        $group = "CSC.All.Eur.MCS.PCS"
    }
      "*PRD_DOORS_START_BOX_BOX_BOX_PAT*" {
        $distrib = "TESTcommandcentre@test.com,csccatia.support@test.com,IMSUKNTOPS_MAIL@test.com,pnixon@test.com,adugdale@test.com"
        $group = "csc.pre.as.baan"
    }
    "*FAILURE*PRD_TEST_*LN_WEEK_PHX_B24*" {
        $distrib = "TEST-Bair-TEST@BairAutosys.test.xmatters.com,TESTcommandcentre@test.com,arjun.ganatra@test.com,colin.jack@test.com,baan_faults@test.com,mbusscc.airerp@test.com,IMSUKNTOPS_MAIL@test.com,ccampb21@test.com,zpatel2@test.com,mkeefe@test.com,yali2@test.com,abullen1@test.com,pnixon@test.com,michael.robinson13@test.com,ian.scarborough@test.com,matthew.goldsmith@test.com,helen.brown2@test.com,colin.rooney@test.com,tom.mcnicholas@test.com,rachel.smart3@test.com,matthew.ainsworth@test.com,thomas.booth@test.com,andrew.parker9@test.com"
        $group = "CSC.All.Eur.MCS.PCS"
    }
    "*SUCCESS*PRD_TEST_*LN_WEEK_PHX_B24*" {
        $distrib = "TESTcommandcentre@test.com,arjun.ganatra@test.com,colin.jack@test.com,baan_faults@test.com,mbusscc.airerp@test.com,IMSUKNTOPS_MAIL@test.com,pnixon@test.com,abullen1@test.com,michael.robinson13@test.com,ian.scarborough@test.com,matthew.goldsmith@test.com,helen.brown2@test.com,colin.rooney@test.com,tom.mcnicholas@test.com,rachel.smart3@test.com,matthew.ainsworth@test.com,thomas.booth@test.com,andrew.parker9@test.com,ccampb21@test.com,zpatel2@test.com,mkeefe@test.com,yali2@test.com"
        $group = "CSC.All.Eur.MCS.PCS"
    }
    "*PRD_TEST_GLKA*B73*" { 
        $distrib = "ccampb21@test.com,systemsoperations.finance@test.com,mbusscc.airerp@test.com,baan_faults@test.com,pnixon@test.com"
        $group = "CSC.All.Eur.MCS.PCS"
    }
    "*PRD_TEST_GLKA*B76*" {
        $distrib = "ian.mellor3@test.com,daz.wren@test.com,matt.cooker@test.com,mbusscc.airerp@test.com,baan_faults@test.com,pnixon@test.com"
        $group = "CSC.All.Eur.MCS.PCS"
    }
    "*PRD_TEST_GLKA*B78*" {
        $distrib = "fsinvoicingservice@test.com,pnixon@test.com,baan_faults@test.com"
        $group = "CSC.All.Eur.MCS.PCS"
    }
    "*PRD_TEST_GLKA*B81*" {
        $distrib = "abullen1@test.com,ccampb21@test.com,mbusscc.airerp@test.com,baan_faults@test.com,pnixon@test.com"
        $group = "CSC.All.Eur.MCS.PCS"
    }
    "*PRD_TEST_GLKA*B89*" {
        $distrib = "abullen1@test.com,ccampb21@test.com,systemsoperations.finance@test.com,mbusscc.airerp@test.com,baan_faults@test.com,pnixon@test.com"
        $group = "CSC.All.Eur.MCS.PCS"
    }
    "*PRD_TEST_GLKA*B91*" {
        $distrib = "abullen1@test.com,ccampb21@test.com,systemsoperations.finance@test.com,mbusscc.airerp@test.com,baan_faults@test.com,pnixon@test.com"
        $group = "CSC.All.Eur.MCS.PCS"
    }
    "*PRD_TEST_GLKA*B84*" {
        $distrib = "simon.bridge@test.com,dan.mcnicholls@test.com,judith.mellor2@test.com,sue.leech@test.com,airuk2r@test.com,Systemsoperations.Finance@test.com,kenneth.swarbrick@test.com,pnixon@test.com,baan_faults@test.com"
        $group = "CSC.All.Eur.MCS.PCS"
    }
    "*PRD_TEST_*BV_ARCHIVING*" {
        $distrib = "mbusscc.airerp@test.com,michael.robinson13@test.com,matthew.goldsmith@test.com,rachel.smart3@test.com,matthew.ainsworth@test.com,thomas.booth@test.com,andrew.parker9@test.com,baan_faults@test.com,pnixon@test.com"
        $group = "CSC.All.Eur.MCS.PCS"
    }
    "*PRD_TEST*EAM*" {
        $distrib = "mbusscc.airerp@test.com,baan_faults@test.com,pnixon@test.com,abullen1@test.com,ccampb21@test.com,zpatel2@test.com,mkeefe@test.com,yali2@test.com"
        $group = "CSC.All.Eur.MCS.PCS"
    }
    "*PRD_TEST*FW*" {
        $distrib = "baan_faults@test.com,pnixon@test.com"
        $group = "CSC.All.Eur.MCS.PCS"
    }
    "*PRD_TEST_NETBACKUP_TEST4078V_CHECK_SERVER_BACKUP_*" {
          $distrib="baan_faults@test.com,pnixon@test.com"
          $group="CSC.All.Eur.MCS.Storage"
    }
    "*PRD_TEST_NETBACKUP_CHECK_TEST4078V_TAPEBACKUP_*" {  
      $distrib="baan_faults@test.com,pnixon@test.com"
      $group="CSC.All.Eur.MCS.Storage"
    }
    "*PRD_TEST_NETBACKUP_baesvlmds153v_CHECK_SERVER_BACKUP_*" {
      $distrib="baan_faults@test.com,pnixon@test.com"
      $group="CSC.All.Eur.MCS.Storage"
    }
    "*PRD_TEST_NETBACKUP_baesvlmds339v_CHECK_SERVER_BACKUP_*" {
      $distrib="baan_faults@test.com,pnixon@test.com"
      $group="CSC.All.Eur.MCS.Storage"
    }
    "*PRD_TEST_*NETBACKUP*" {
      $distrib="baan_faults@test.com,TESTcommandcentre@test.com,IMSUKNTOPS_MAIL@test.com,pnixon@test.com"
      $group="CSC.All.Eur.MCS.Storage"
    }
    "PRD_TEST_*STOP*" {
      $distrib="baan_faults@test.com,TESTcommandcentre@test.com,IMSUKNTOPS_MAIL@test.com,pnixon@test.com"
      $group="csc.pre.as.baan"
    }
    "*TEST_KABA_*STOP*" {
      $distrib="TESTcommandcentre@test.com,IMSUKNTOPS_MAIL@test.com,pnixon@test.com,gblackhu@test.com,skamins2@test.com"
      $group="csc.pre.as.baan"
    }
    "*TEST_KABA_*START*" {
      $distrib="IMSUKNTOPS_MAIL@test.com,pnixon@test.com,gblackhu@test.com,skamins2@test.com"
      $group="csc.pre.as.baan"
    }
    "*PRD_DOORS_*" {
     $distrib="TESTcommandcentre@test.com,IMSUKNTOPS_MAIL@test.com,pnixon@test.com,csccatia.support@test.com"
     $group="csc.pre.as.baan"
    }
    "*PRD_TEST_*START*" {
     $distrib="baan_faults@test.com,TESTcommandcentre@test.com,IMSUKNTOPS_MAIL@test.com,pnixon@test.com"
     $group="csc.pre.as.baan"
    }
    "*PRD_TEST_*LN*" {
     $distrib="baan_faults@test.com,mbusscc.airerp@test.com,TESTcommandcentre@test.com,IMSUKNTOPS_MAIL@test.com,pnixon@test.com,michael.robinson13@test.com,ian.scarborough@test.com,matthew.goldsmith@test.com,helen.brown2@test.com,colin.rooney@test.com,tom.mcnicholas@test.com,rachel.smart3@test.com,matthew.ainsworth@test.com,thomas.booth@test.com,andrew.parker9@test.com,abullen1@test.com,ccampb21@test.com,zpatel2@test.com,mkeefe@test.com,yali2@test.com"
     $group="csc.pre.as.baan"
    }
    }

# User SECTION
# ------------

# Header text lines
$LINE1 = "BAE TEST(DEV) Batch Alert on Autosys Workload Automation"
$LINE2 = "-----------------------------------------------------------"
$LINE3 = Get-Date
$LINE4 = ""
$LINE5 = ""

# Create email text based on the alert type
switch -Wildcard ($args -join '') {
   "*MACH_OFFLINE*" {  
    $subject="TEST(PRD) Machine/Agent OFFLINE Alert : Machine $5 ** Please Investigate **"
                                         $LINE6="Machine: $5"
                                         $LINE7=""
                                         $LINE8=""
                                         $LINE9=""
                                         $LINE10="This Machine/Agent is OFFLINE and needs to be Investigated ASAP as it will impact the Scheduling"
                                         $LINE11=""
                                         $LINE12="Please Restart the Machine/Agent - Logon to the Server, go into Services and START CA Workload Automation Agent. If any further issues please contact Application Support On Call Support Team Member on xxxxx xxxxxx."
                                         $LINE13=""
                                                }
"*SUCCESS*PRD_TEST_*B73*" {  
    $subject="TEST(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                                        $LINE6="Job:     ${JOB}"
                                                        $LINE7="Status:  ${STATUS}"
                                                        $LINE8="Machine: ${MACHINE}"
                                                        $LINE9=""
                                                        $LINE10="Job has successfully completed (Information ONLY)"
                                                        $LINE11=""
                                                        $LINE12="The log file generated for this run can be found on the server TEST3632v within the directory: "
                                                        $LINE13="d:/infor/bse/xch/412/hoursulg/log"
                                                              }
"*SUCCESS*PRD_TEST_*B81*" {  
    $subject="TEST(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                                        $LINE6="Job:     ${JOB}"
                                                        $LINE7="Status:  ${STATUS}"
                                                        $LINE8="Machine: ${MACHINE}"
                                                        $LINE9=""
                                                        $LINE10="Job has successfully completed (Information ONLY)"
                                                        $LINE11=""
                                                        $LINE12=""
                                                        $LINE13=""
                                                              }
"*SUCCESS*PRD_TEST_STOP_BOX_BOX_BOX_PAT*" {  
    $subject="TEST(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                                        $LINE6="Job:     ${JOB}"
                                                        $LINE7="Status:  ${STATUS}"
                                                        $LINE8="Machine: ${MACHINE}"
                                                        $LINE9=""
                                                        $LINE10="Job has successfully completed (Information ONLY)"
                                                        $LINE11=""
                                                        $LINE12="The Application Stop schedule is now complete and all the TEST Applications should now be unavailable to users so monthly patching can begin."
                                                        $LINE13=""
                                                             }
"*SUCCESS*TEST_KABA_STOP_BOX_BOX_BOX_PAT*" {  
    $subject="KABA(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                                        $LINE6="Job:     ${JOB}"
                                                        $LINE7="Status:  ${STATUS}"
                                                        $LINE8="Machine: ${MACHINE}"
                                                        $LINE9=""
                                                        $LINE10="Job has successfully completed (Information ONLY)"
                                                        $LINE11=""
                                                        $LINE12="The Application Stop schedule is now complete and all the KABA Applications should now be unavailable to users so monthly patching can begin."
                                                        $LINE13=""
                                                              }
"*SUCCESS*PRD_TEST_START_BOX_BOX_BOX_REL*" { 
     $subject="TEST(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                                        $LINE6="Job:     ${JOB}"
                                                        $LINE7="Status:  ${STATUS}"
                                                        $LINE8="Machine: ${MACHINE}"
                                                        $LINE9=""
                                                        $LINE10="Job has successfully completed (Information ONLY)"
                                                        $LINE11=""
                                                        $LINE12="The Application Start schedule is now complete and the backups taken, all the TEST Applications should now be available. The system is NOW ready for the release window to begin."
                                                        $LINE13=""
                                                              }
"*SUCCESS*PRD_TEST_START_BOX_BOX_BOX_*" {    
  $subject="TEST(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                                        $LINE6="Job:     ${JOB}"
                                                        $LINE7="Status:  ${STATUS}"
                                                        $LINE8="Machine: ${MACHINE}"
                                                        $LINE9=""
                                                        $LINE10="Job has successfully completed (Information ONLY)"
                                                        $LINE11=""
                                                        $LINE12="The Application Start schedule is now complete and all the TEST Applications should now be available to users except during scheduled maintenance."
                                                        $LINE13=""
                                                              }
"*SUCCESS*PRD_TEST_TEST3632V_LN_REINDEXING_*_1800_BOX_SAT*" {   
   $subject="TEST(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                                        $LINE6="Job:     ${JOB}"
                                                        $LINE7="Status:  ${STATUS}"
                                                        $LINE8="Machine: ${MACHINE}"
                                                        $LINE9=""
                                                        $LINE10="Job has successfully completed (Information ONLY)"
                                                        $LINE11=""
                                                        $LINE12="The Reindexing schedule is now complete and all the TEST LN Applications should now be available to users."
                                                        $LINE13=""
                                                              }
"*SUCCESS*TEST_KABA_START_BOX_BOX_BOX*" {   
   $subject="KABA(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                                        $LINE6="Job:     ${JOB}"
                                                        $LINE7="Status:  ${STATUS}"
                                                        $LINE8="Machine: ${MACHINE}"
                                                        $LINE9=""
                                                        $LINE10="Job has successfully completed (Information ONLY)"
                                                        $LINE11=""
                                                        $LINE12="The Application Start schedule is now complete after patching and all the KABA Applications should now be available to users except during scheduled maintenance."
                                                        $LINE13=""
                                                              }
"*SUCCESS*PRD_DOORS_START_BOX_BOX_BOX*" { 
    $subject="DOORS(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                                        $LINE6="Job:     ${JOB}"
                                                        $LINE7="Status:  ${STATUS}"
                                                        $LINE8="Machine: ${MACHINE}"
                                                        $LINE9=""
                                                        $LINE10="Job has successfully completed (Information ONLY)"
                                                        $LINE11=""
                                                        $LINE12="The Application Start schedule is now complete after patching and all the DOORS Applications should now be available to users except during scheduled maintenance."
                                                        $LINE13=""
                                                             }
"*SUCCESS*" { 
     $subject="TEST(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                         $LINE6="Job:     ${JOB}"
                                         $LINE7="Status:  ${STATUS}"
                                         $LINE8="Machine: ${MACHINE}"
                                         $LINE9=""
                                         $LINE10="Job has successfully completed (Information ONLY)"
                                         $LINE11=""
                                         $LINE12=""
                                         $LINE13=""
                                                }
"*RUNNING*STOP*BOX*PAT*" { 
     $subject="TEST(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                         $LINE6="Job:     ${JOB}"
                                         $LINE7="Status:  ${STATUS}"
                                         $LINE8="Machine: ${MACHINE}"
                                         $LINE9=""
                                         $LINE10="Job is in a status of RUNNING"
                                         $LINE11="OPS Please Start to Monitor the STOP Scheduling to ensure the BOX - PRD_TEST_STOP_BOX_BOX_BOX_PAT and"
                                         $LINE12="all its SUB BOX's complete as the LN Servers/System are shutting DOWN for PATCHING activities, once complete you will receive notification to begin your activities."
                                         $LINE13=""
                                                }
"*RUNNING*KABA*STOP*BOX*PAT*" {    
  $subject="KABA(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                         $LINE6="Job:     ${JOB}"
                                         $LINE7="Status:  ${STATUS}"
                                         $LINE8="Machine: ${MACHINE}"
                                         $LINE9=""
                                         $LINE10="Job is in a status of RUNNING"
                                         $LINE11="OPS Please Start to Monitor the STOP Scheduling to ensure the BOX - TEST_KABA_STOP_BOX_BOX_BOX_PAT and"
                                        $LINE12="all its SUB BOX's complete as the KABA Servers/System are shutting DOWN for PATCHING activities, once complete you will receive notification to begin your activities."
                                         $LINE13=""
                                                }
"*RUNNING*STOP*BOX*" {    
  $subject="TEST(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                         $LINE6="Job:     ${JOB}"
                                         $LINE7="Status:  ${STATUS}"
                                         $LINE8="Machine: ${MACHINE}"
                                         $LINE9=""
                                         $LINE10="Job is in a status of RUNNING"
                                         $LINE11="OPS Please Start to Monitor the STOP/NETBACKUP/START Scheduling to ensure the BOX - PRD_TEST_STOP_NETBACKUP_START_BOX_BOX_BOX_day and"
                                         $LINE12="all its SUB BOX's complete as the LN Servers/System is DOWN until this process fully completes SUCCESSFULLY, once complete the LN Batch will START"
                                         $LINE13=""
                                                }
"*RUNNING*PRD_TEST_TEST3632V_LN_REINDEXING_*_1800_BOX_SAT*" {    
  $subject="TEST(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                         $LINE6="Job:     ${JOB}"
                                         $LINE7="Status:  ${STATUS}"
                                         $LINE8="Machine: ${MACHINE}"
                                         $LINE9=""
                                         $LINE10="Job is in a status of RUNNING"
                                         $LINE11="The Reindexing schedule has started and the TEST LN Application will be unavailable to end users for upto 6 hours. Please ignore the BaanLogicService alerts in Nagios for TEST3630v/TEST3631v."
                                         $LINE12="Once the Reindexing schedule is complete you will receive an email detailing its success."
                                         $LINE13=""
                                                }
"*RUNNING*" {     
 $subject="TEST(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                         $LINE6="Job:     ${JOB}"
                                         $LINE7="Status:  ${STATUS}"
                                         $LINE8="Machine: ${MACHINE}"
                                         $LINE9=""
                                         $LINE10="Job is in a status of RUNNING"
                                         $LINE11=""
                                         $LINE12=""
                                         $LINE13=""
                                                }
"*TERMINATED*" {   
 $subject="TEST(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                         $LINE6="Job:     ${JOB}"
                                         $LINE7="Status:  ${STATUS}"
                                         $LINE8="Machine: ${MACHINE}"
                                         $LINE9=""
                                         $LINE10="Job has been manually terminated"
                                         $LINE11=""
                                         $LINE12=""
                                         $LINE13=""
                                                }
"*FAILURE*PRD_TEST_*B76*EXITCODE:*120*" {    
  $subject="TEST(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                                        $LINE6="Job:     ${JOB}"
                                                        $LINE7="Status:  ${STATUS}"
                                                        $LINE8="Retcode: ${RETCODE}"
                                                        $LINE9="Machine: ${MACHINE}"
                                                        $LINE10=""
                                                        $LINE11="Batch job has completed successfully, however some rows were not loaded into LN due to errors, refer to log file for details."
                                                        $LINE12=""
                                                        $LINE13="The logfile can be found on TEST3619V in Test\Bulk_Uploads\UPD_T02 it will be the latest log.EXE.*.1 file."
                                                              }
"*PRD_TEST_*B89*SUC-T01*EXITCODE:*" {   
   $subject="TEST(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                                        $LINE6="Job:     ${JOB}"
                                                        $LINE7="Status:  ${STATUS}"
                                                        $LINE8="Retcode: ${RETCODE}"
                                                        $LINE9="Machine: ${MACHINE}"
                                                        $LINE10=""
                                                        $LINE11="Batch job has completed, if it has failed some rows were not loaded into LN due to errors, refer to log file for details."
                                                        $LINE12=""
                                                        $LINE13="The logfile can be found on TEST3619V in Test\SuccessFactors\T01\ErrorLog it will be the latest log.* file."
                                                              }
"*PRD_TEST_*B84*EXITCODE:*120*" {    
  $subject="TEST(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                                        $LINE6="Job:     ${JOB}"
                                                        $LINE7="Status:  ${STATUS}"
                                                        $LINE8="Retcode: ${RETCODE}"
                                                        $LINE9="Machine: ${MACHINE}"
                                                        $LINE10=""
                                                        $LINE11="Batch job has completed successfully, however some rows were not loaded into LN due to errors, refer to log file for details."
                                                        $LINE12=""
                                                        $LINE13="The logfile can be found on TEST3619V in Test\Bulk_Uploads\T04 it will be the latest log.EXE.*.1 file."
                                                              }
"*FAILURE*PRD_TEST_*B78*EXITCODE:*120*" {   
   $subject="TEST(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                                        $LINE6="Job:     ${JOB}"
                                                        $LINE7="Status:  ${STATUS}"
                                                        $LINE8="Retcode: ${RETCODE}"
                                                        $LINE9="Machine: ${MACHINE}"
                                                        $LINE10=""
                                                        $LINE11="Batch job has completed successfully, however some rows were not loaded into LN due to errors, refer to log file for details."
                                                        $LINE12=""
                                                        $LINE13="The logfile can be found on TEST3632V in D:\Infor\bse\xch\412\UPD_T03\log it will be the latest log.EXE.*.1 file."
                                                              }
"*FAILURE*PRD_TEST_*EXITCODE:5*" {  
    $subject="TEST(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                                        $LINE6="Job:     ${JOB}"
                                                        $LINE7="Status:  ${STATUS}"
                                                        $LINE8="Retcode: ${RETCODE}"
                                                        $LINE9="Machine: ${MACHINE}"
                                                        $LINE10=""
                                                        $LINE11="Batch job has failed due to access denied, the job will automatically rerun in 30 seconds if no further emails are received it has been successful."
                                                        $LINE12=""
                                                        $LINE13=""
                                                              }
"*FAILURE*PRD_TEST_*BVA-BDS-UMV*" {   
   $subject="TEST(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                                        $LINE6="Job:     ${JOB}"
                                                        $LINE7="Status:  ${STATUS}"
                                                        $LINE8="Retcode: ${RETCODE}"
                                                        $LINE9="Machine: ${MACHINE}"
                                                        $LINE10=""
                                                        $LINE11="Batch job has completed with errors."
                                                        $LINE12=""
                                                        $LINE13="BV Archiving execution of phx_update_max_variation on BV_BDS returned an error. Review log files in D:\BV\Archiving for further information."
                                                              }
"*FAILURE*PRD_TEST_*BVA-CDS-UMV*" {   
  $subject="TEST(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                                        $LINE6="Job:     ${JOB}"
                                                        $LINE7="Status:  ${STATUS}"
                                                        $LINE8="Retcode: ${RETCODE}"
                                                        $LINE9="Machine: ${MACHINE}"
                                                        $LINE10=""
                                                        $LINE11="Batch job has completed with errors."
                                                        $LINE12=""
                                                        $LINE13="BV Archiving execution of phx_update_max_variation on BV_CDS returned an error. Review log files in D:\BV\Archiving for further information."
                                                              }
"*FAILURE*PRD_TEST_*BVA-BDS-DSV*" {   
   $subject="TEST(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                                        $LINE6="Job:     ${JOB}"
                                                        $LINE7="Status:  ${STATUS}"
                                                        $LINE8="Retcode: ${RETCODE}"
                                                        $LINE9="Machine: ${MACHINE}"
                                                        $LINE10=""
                                                        $LINE11="Batch job has completed with errors."
                                                        $LINE12=""
                                                        $LINE13="BV Archiving execution of phx_delete_superseded_variation on BV_BDS returned an error. Review log files in D:\BV\Archiving for further information."
                                                              }
"*FAILURE*PRD_TEST_*BVA-CDS-DSV*" {   
   $subject="TEST(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                                        $LINE6="Job:     ${JOB}"
                                                        $LINE7="Status:  ${STATUS}"
                                                        $LINE8="Retcode: ${RETCODE}"
                                                        $LINE9="Machine: ${MACHINE}"
                                                        $LINE10=""
                                                        $LINE11="Batch job has completed with errors."
                                                        $LINE12=""
                                                        $LINE13="BV Archiving execution of phx_delete_superseded_variation on BV_CDS returned an error. Review log files in D:\BV\Archiving for further information."
                                                              }
"*FAILURE*PRD_TEST_TEST3632V_*PHX_B37_*" {  
    $subject="TEST(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                         $LINE6="Job:     ${JOB}"
                                         $LINE7="Status:  ${STATUS}"
                                         $LINE8="Retcode: ${RETCODE}"
                                         $LINE9="Machine: ${MACHINE}"
                                         $LINE10=""
                                         $LINE11="Job has been manually terminated"
                                         $LINE12="Please invoke callout to Apps Support as the LN Master server is unavailable due to shared memory issues"
                                         $LINE13=""
                                                }
"*FAILURE*PRD_TEST_TEST363*V_*PHX_B37*" {    
  $subject="TEST(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                         $LINE6="Job:     ${JOB}"
                                         $LINE7="Status:  ${STATUS}"
                                         $LINE8="Retcode: ${RETCODE}"
                                         $LINE9="Machine: ${MACHINE}"
                                         $LINE10=""
                                         $LINE11="Job has been manually terminated"
                                         $LINE12="Please invoke callout to Apps Support as the LN Apps server on this node is unavailable due to shared memory issues"
                                         $LINE13=""
                                                }
"*FAILURE*PRD_TEST_TEST3632V_LN_CHECK*" {  
   $subject="TEST(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                         $LINE6="Job:     ${JOB}"
                                         $LINE7="Status:  ${STATUS}"
                                         $LINE8="Retcode: ${RETCODE}"
                                         $LINE9="Machine: ${MACHINE}"
                                         $LINE10=""
                                         $LINE11="One of the batch jobs is in a RUNNING state within LN."
                                         $LINE12="Please invoke callout to Application Support Team(Team Member on xxxxx xxxxxx) and raise a Sev 3 SNOW incident"
                                         $LINE13=""
                                                }
"*FAILURE*PRD_TEST_TEST3632V*PHX_B24C*" {     
 $subject="TEST(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                         $LINE6="Job:     ${JOB}"
                                         $LINE7="Status:  ${STATUS}"
                                         $LINE8="Retcode: ${RETCODE}"
                                         $LINE9="Machine: ${MACHINE}"
                                         $LINE10=""
                                         $LINE11="The above batch job has failed within LN, please raise a Sev 2 SNOW incident and assign to Application Support - and inform MIM."
                                         $LINE12="An automated call from Xmatters will be placed to Application Support Team(Team Member on xxxxx xxxxxx) if no response within 30 minutes please contact the support number."
                                         $LINE13=""
                                                }
"*FAILURE*PRD_TEST_*EAM*" {  
    $subject="EAM-ETL(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                         $LINE6="Job:     ${JOB}"
                                         $LINE7="Status:  ${STATUS}"
                                         $LINE8="Retcode: ${RETCODE}"
                                         $LINE9="Machine: ${MACHINE}"
                                         $LINE10=""
                                         $LINE11="Please note the above batch job has failed within EAM_ETL please investigate."
                                         $LINE12=""
                                         $LINE13=""
                                                }
"*FAILURE*PRD_TEST_*_START_*" {   
   $subject="TEST(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                         $LINE6="Job:     ${JOB}"
                                         $LINE7="Status:  ${STATUS}"
                                         $LINE8="Retcode: ${RETCODE}"
                                         $LINE9="Machine: ${MACHINE}"
                                         $LINE10=""
                                         $LINE11="One of the Application start jobs has failed, it will attempt 5 reruns a minute apart. If you do not receive another email alert within a minute the rerun was successful"
                                         $LINE12="and you can ignore this message and you will get an email with the PRD_TEST_START_BOX_BOX_BOX completion which indicates the success of the backup sequence. If the job is still failing after 5 reruns please callout Application Support and raise a sev 2 SNOW incident."
                                         $LINE13=""
                                                }
"*FAILURE*" {      
$subject="TEST(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                         $LINE6="Job:     ${JOB}"
                                         $LINE7="Status:  ${STATUS}"
                                         $LINE8="Retcode: ${RETCODE}"
                                         $LINE9="Machine: ${MACHINE}"
                                         $LINE10=""
                                         $LINE11=""
                                         $LINE12=""
                                         $LINE13=""
                                                }
"*MAXRUNALARM*PRD_TEST_TEST363*V_*PHX_B37*" {  
    $subject="TEST(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                         $LINE6="Job:     ${JOB}"
                                         $LINE7="Status:  ${STATUS}"
                                         $LINE8="Retcode: ${RETCODE}"
                                         $LINE9="Machine: ${MACHINE}"
                                         $LINE10=""
                                         $LINE11="Job has exceeded maximum run time"
                                         $LINE12="Please invoke callout to Apps Support as the LN Apps server on this node is unavailable due to shared memory issues"
                                         $LINE13=""
                                                }
"*MAXRUNALARM*PRD_TEST_STOP_BOX_BOX_BOX*" { 
 $subject="TEST(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                         $LINE6="Job:     ${JOB}"
                                         $LINE7=""
                                         $LINE8=""
                                         $LINE9=""
                                         $LINE10="The STOP Application schedule has exceeded its maximum run time"
                                         $LINE11="Please raise a Sev 3 SNOW incident and assign to Application Support -  An automated callout via Xmatters to Application Support Team(Team Member on xxxxx xxxxxx) will be made if no response within 30 minutes please contact the support number provided."
                                         $LINE12=""
                                         $LINE13=""
                                                }
"*MUST_START*PRD_TEST_START_BOX_BOX_BOX*" { 
 $subject="TEST(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                         $LINE6="Job:     ${JOB}"
                                         $LINE7=""
                                         $LINE8=""
                                         $LINE9=""
                                         $LINE10="The START Application schedule has not begun by 21:25 and need investigation."
                                         $LINE11="Please raise a Sev 3 SNOW incident and assign to Application Support . An automated callout via Xmatters to Application Support Team(Team Member on xxxxx xxxxxx) will be made if no response within 30 minutes please contact the support number provided."
                                         $LINE12=""
                                         $LINE13=""
                                                }
"*MAXRUNALARM*PRD_TEST_START_BOX_BOX_BOX*" { 
 $subject="TEST(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                         $LINE6="Job:     ${JOB}"
                                         $LINE7=""
                                         $LINE8=""
                                         $LINE9=""
                                         $LINE10="The START Application schedule has not completed on time."
                                         $LINE11="Please check Autosys schedule to investigate issue and if unable to determine please invoke callout to Application Support Team(Team Member on xxxxx xxxxxx)"
                                         $LINE12=""
                                         $LINE13=""
                                       }
"*MAXRUNALARM*PRD_TEST*EAM*" {  
 $subject="EAM - ETL(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                         $LINE6="Job:     ${JOB}"
                                         $LINE7=""
                                         $LINE8=""
                                         $LINE9=""
                                         $LINE10="The EAM ETL job has not completed on time and overun its maximum runtime."
                                         $LINE11="The next job will not start until this job has completed."
                                         $LINE12=""
                                         $LINE13=""
                                       }      
"*MAXRUNALARM*" { 
 $subject="TEST(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                         $LINE6="Job:     ${JOB}"
                                         $LINE7=""
                                         $LINE8=""
                                         $LINE9=""
                                         $LINE10="Job has exceeded its maximum run time"
                                         $LINE11=""
                                         $LINE12=""
                                         $LINE13=""
                                                }
"*MINRUNALARM*" { 
 $subject="TEST(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                         $LINE6="Job:     ${JOB}"
                                         $LINE7=""
                                         $LINE8=""
                                         $LINE9=""
                                         $LINE10="Job has ended before its minimum run time"
                                         $LINE11=""
                                         $LINE12=""
                                         $LINE13=""
                                                }
    }

# Create the text file for the email
$EmailContent = @"
-----------------------------------------------------
$LINE1
$LINE2
$LINE3
$LINE4
$LINE5
$LINE6
$LINE7
$LINE8
$LINE9
$LINE10
$LINE11
$LINE12
$LINE13

Application Support Autosys Administration
"@

Set-Content -Path $TEXTFILE -Value $EmailContent

# Send the email
if ($distrib -ne "") {
    Send-MailMessage -To $distrib.Split(",") -From AutosysAdmin@test.com -Subject $subject -Body (Get-Content -Path $TEXTFILE -Raw) -SmtpServer apprelay.testlnk.net

  
}

exit`Preformatted text`
type or paste code here
````Preformatted text`

Welcome to the forum, for starters please go back and use the button ‘</>’ to format code as code.

Hi neemobeer,

Thanks for the response I have used to ‘</>’ to format the code now I hope.

regards

Paul

i think maybe your code formatting didn’t get laid down correctly so I might be making some assumptions here. (hint: just start a line with 3 backticks, then paste your code below, then end with a new line that also has 3 backticks).
I think what I’m seeing is you call the script by name and then you’re supplying this as the arguments?
CAUAJM_I_40245 EVENT: CHANGE_STATUS STATUS: SUCCESS JOB: PRD_TEST_BOX_BOX_BOX_REL
Since Powershell would interpret each thing, separated by a space, as the arguments then I think I’m correctly reproducing your test with this code instead:

$Test = "CAUAJM_I_40245 EVENT: CHANGE_STATUS STATUS: SUCCESS JOB: PRD_TEST_BOX_BOX_BOX_REL" -split " "
$STATUS = $Test[4]
$JOB = $Test[6]
$MACHINE = $Test[8]
$RETCODE = $Test[10]

With $STATUS being “SUCCESS” and $JOB being “PRD_TEST_BOX_BOX_BOX_REL” and the other two are null.
If we follow that logic then, your switch statement is getting all of the arguments joined together without spaces. Mine would look like this then:

PS #> $Test -join ''
CAUAJM_I_40245EVENT:CHANGE_STATUSSTATUS:SUCCESSJOB:PRD_TEST_BOX_BOX_BOX_REL

When I run that through the switch block nothing matches.
It shouldn’t match the PRD_TEST_*START one because the word start isn’t in the string and it can’t match the PRD_TEST_BOX_BOX_BOX_REL one because there isn’t one in there that has that exact string in it, or even something with wildcards that would partially match.

This is honestly really confusing to look at. I love that you’re using a switch statement for it instead of a bunch of if/else statements but there’s like 30 statements in there and lots of combinations of wildcards.

I know I don’t have the whole story here, but I’d be inclined to maybe leverage a parameter statement and/or do some kind of better parsing on that input so you could clearly define each piece of data and more appropriately form logic around that.

Hi greyout,

Thank you so much for the taking the time to respond apologies I missed typed the input line it should have been CAUAJM_I_40245 EVENT: CHANGE_STATUS STATUS: SUCCESS JOB: PRD_TEST_START_BOX_BOX_BOX_REL. so it should be looking for status $STATUS = SUCCESS and $JOB = PRD_TEST_START_BOX_BOX_BOX_REL. I was hoping that the code would then set the distribution list to the below but it doesnt pick out the closest match.

"*PRD_TEST_START_BOX_BOX_BOX_REL*" {
        $distrib = "TESTcommandcentre@test.com,IMSUKNTOPS_MAIL@test.com,pnixon@test.com,abullen1@test.com,ccampb21@test.com,mkeefe@test.com,yali2@test.com,zpatel2@test.com"

and text to

"*SUCCESS*PRD_TEST_START_BOX_BOX_BOX_REL*" { 
     $subject="TEST(PRD) Batch Alert : Job ${JOB} - status ${STATUS}"
                                                        $LINE6="Job:     ${JOB}"
                                                        $LINE7="Status:  ${STATUS}"
                                                        $LINE8="Machine: ${MACHINE}"
                                                        $LINE9=""
                                                        $LINE10="Job has successfully completed (Information ONLY)"
                                                        $LINE11=""
                                                        $LINE12="The Application Start schedule is now complete and the backups taken, all the TEST Applications should now be available. The system is NOW ready for the release window to begin."
                                                        $LINE13=""

What would be the best way of using the switch statement so it scans down the relevant distribution list and email event and picks out the most relevant string from the code. Am I doing something wrong in my coding?

I am basically just trying to send an email to the distribution list which closest match to the Job or Status output and then send the email body of text based also on the closest match to the Job or Status output.

Thank You

regards

Paul

Sorry on mobile for a bit.
Can we maybe talk about some other parts of this?
Do you know how many unique combinations of destination emails there are? I.e. are there scenarios where multiple jobs and statuss would get sent to the same recipients?

How is this job status getting fed to the PowerShell script? Where does it come from? Is its structure fairly consistent? I’m still thinking in my head there’s gotta be a better way than just joining all the $args together and using wildcards. But i don’t know what all the possibilities are so I don’t want to bark up the wrong tree.

It is actually sending it to the distribution list below

“*PRD_TEST_START” {
$distrib="baan_faults@test.com,TESTcommandcentre@test.com,IMSUKNTOPS_MAIL@test.com,pnixon@test.com"
$group=“csc.pre.as.baan”
}


XXX PHOENIX(DEV) Batch Alert on Autosys Workload Automation

07/26/2024 09:02:21

Job: PRD_TEST_START_BOX_BOX_BOX_REL
Status: SUCCESS
Machine:

Job has successfully completed (Information ONLY)

DXC Application Support Autosys Administration

Hi Greyout,

The script was running on linux but we moved across to windows so I converted it to powershell using and AI conversion tool and this was the script it suggested to use.

The job status is being fed into the powershell script from a tool called NSM Event Management which allows you to automate responses to certain situations from our batch scheduling tool.

We have thousand of jobs running but on specific jobs we need to send out email notifications warnings as some of the email addresses trigger a callout to the ON CALL support.

The structure of the messages being passed to the alert is the same with the exception of the status, job name, machine and exit code which are the variables. We only really use the status, job name and exit code to determine the distribution list the specific job needs to be sent to and the correct text to be attached within the email.

The script should scan down all the variable inputs and send the email and the text of the email to the distribution list which matches the status, job or exit code, some it might be a combination of all 3 and some it might just be the status and then it adds the text which matches the input the closest.

Thank You

regards

Paul

Hi Greyout

Just to add I really appreciate your help with this.

Thank You

regards

Paul

Paul,

If I were troubleshooting this script, I would add a start-transcript at the beginning and several write-host commands throughout the script, so you can see what it’s actually doing. For example, I would write-host each of the arguments, to make sure the argument values actually line up with what I expect them to be. I would write-host in each of the elements in the switch statements so you know for sure which option it landed on. I would also comment out the send-mailmessage so the script can be tested without spamming recipients with test messages - the write-host statements should put all the same information to the screen to be captured in the transcript.

From an overall code perspective, I haven’t dug deeply enough to understand all the cases you are passing in, but I would try to compile conditions based on each argument instead of joining them and using wildcards, if that’s possible. It would make the code easier to comprehend.

Darwin

1 Like

@psdarwin covered what I would do.

@pnixon1953 please remember to always format your code as “preformatted text” by either putting 3x backticks before and after any mention of code, or highlight it all and use the </> button for “preformatted text” when editing a message.

I’m going to reiterate what Darwin said and repeat myself, but if it were me I would want to know/understand all of the possible output from NSM Event Management. Then based on that output I would probably use something like Regex to parse it into fields that make sense to us like “Job” and “Status” etc.
Then I would figure out all the possible recipient combinations that might exist for different scenarios and spell those out. Like, what combinations of Job and Status = DistributionA, etc.
Once all of those are defined then I would also probably use a switchblock based on the Job and the Status.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.