title: PowerShell script to look for number and if greater than send email
body: <p>I am looking for a script that runs a command, reads the output and then if a number is greater than...send an email. </p>
  
  <p>This is the code I have so far -</p>
  
  <pre><code>$Output = 'D:\test.data\QueuedJobss.txt'
  d:
  set-location -Path 'D:\program files\veritas\netbackup\bin\admincmd'
  .\bpdbjobs -summary -L &gt; $Output
  
  $Queued = (Select-String -Pattern "Queued:\s+(\d+)" -Path $Output).Matches.Groups[1].Value
  
  if ($Queued -gt 100 ) {
    $MailArgs = @{
          'To'          = 'ab2112@test.com'
          'From'        = 'netbackup@test.com'
          'Subject'     = 'Over 100 Queued Jobs!'
          'Attachments' = $Output
          'Body'        = 'Check Environment'
  
          'SmtpServer' = 'smtp.us.test.com'
         }
       Send-MailMessage @MailArgs
    }
  </code></pre>
  
  <p>It is currently returning an error - </p>
  
  <pre><code>}
  Cannot index into a null array.
  At line:6 char:81
  + $Queued = (Select-String -Pattern "Queued:\s+(\d+)" -Path $Output).Match.Groups[ &lt;&lt;&lt;&lt; 1].Value
      + CategoryInfo          : InvalidOperation: (1:Int32) [], RuntimeException
      + FullyQualifiedErrorId : NullArray
  </code></pre>
  
  <p>The output that it's reading looks like - </p>
  
  <pre><code>Summary of jobs on ustestnbma01
  Queued:                                1
  Waiting-to-Retry:                        0
  Active:                           5
  Successful:                   25876
  Partially Successful:           136
  Failed:                         327
  Incomplete:                       0
  Suspended:                        0
  Total:                        26345
  </code></pre>
  
  <p>The row I'm focused on is Queued, that number is followed by a lot of spaces.</p>