Powershell脚本用于读取输出,如果数字比发送电子邮件好

时间:2018-05-18 13:44:52

标签: powershell

我有当前脚本正在读取一个文件,其中包含Queued:和一个后跟大量空格的数字。如果该数字大于100,它将向我发送电子邮件

$Output = 'D:\alec.data\QueuedJobss.txt'
d:
set-location -Path 'D:\program files\veritas\netbackup\bin\admincmd'
.\bpdbjobs -summary -L > $Output

$Queued = (Select-String -Pattern "Queued:\s+(\d+)" -Path $Output).Matches.Groups[1].Value

if ($Queued -gt 100 ) {
  $MailArgs = @{
        'To'          = 'alb2112@test.com'
        'From'        = 'netbackup@test.com'
        'Subject'     = 'Over 100 Queued Jobs!'
        'Attachments' = $Output
        'Body'        = 'Check Environment'

        'SmtpServer' = 'smtp.test.com'
       }
     Send-MailMessage @MailArgs
  }

我不太熟悉使用这些表达式cmds来帮助理解空间。如果在没有使用表达式的情况下有其他解决方案,请告诉我。它正在读取的输出看起来像这样 -

Summary of jobs on ustest01
Queued:                                0
Waiting-to-Retry:                        0
Active:                          43
Successful:                   25391
Partially Successful:           113
Failed:                         184
Incomplete:                       0
Suspended:                        0
Total:                        25731

它收到以下错误,说它无法索引到空数组。它似乎与表达式有问题 -

    Cannot index into a null array.
At line:6 char:88
+ [int]$Queued = (Select-String -Pattern "Queued:\s+(\d+)" -Path $Output).Matches.Groups[ <<<< 1].Value
    + CategoryInfo          : InvalidOperation: (1:Int32) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

0 个答案:

没有答案