title: Try/Catch block in script not working
body: <p>The premise of the script below is that I need it to look through a folder of PDFs which will be named after the individual they are for, this will then match the name to an email in an accompanying CSV file and generate an email which sends the appropriate PDFs to them.</p>
  
  <p>The problem is we have a send/receive limit of 10MB, so I've been trying to figure out a <code>try/catch</code> block which will email someone if some PDFs fail to send, but in it's current state it seems to stop the script if it encounters an error and doesn't send messages to anyone else.</p>
  
  <p>Can someone provide some suggestions on maybe how to get this working, or any better solutions?</p>
  
  <p>I have been looking at <code>do/while</code> to see if I can get it to loop until the attachments being sent are equal to 10MB and then send that message and restart but can't figure it out.</p>
  
  <p>Any assistance is GREATLY appreciated, and let me know if anything is wrong/you need more info.</p>
  
  <pre><code>$CSV = Import-Csv "\\Server\Share\NamesAndEmails.csv"
  $PDFFolder = "\\Server\Share\PDF Folder"
  
  $ErrorActionPreference = "Continue"
  
  ForEach($User in $CSV)
  {
      $PDFs = Get-ChildItem -Path $PDFFolder | Where-Object { $_.Extension -eq ".pdf" -and $_.Name -like "*$($User.Name)*" }
  
      $to = $User.Email
      $from = "email@domain.com"
      $smtp = "smtp.domain.com"
      $body = "Please see attachments."
      $attachments = @()
  
      ForEach($PDF in $PDFs)
      {
          $attachments += $PDF.FullName
      }
  
      $MessageParameters = @{
          From = $from
          To = $to
          Subject = "Email subject"
          Body = $body
          SmtpServer = $smtp
          Attachments = $attachments
      } 
  
      try 
      { 
          Send-MailMessage @MessageParameters 
      } 
      Catch 
      {            
          Send-MailMessage `
              -smtp smtp.domain.com `
              -to "Name &lt;email@domain.com&gt;" `
              -from "Name &lt;email@domain.com&gt;" `
              -subject "Failed to send post for $($user.Name)" `
              -body "Please go to \\... and resend PDF's for $($user.name) across multiple messages as necessary." `
      }
  }
  </code></pre>