-1

I have a script that's running a command, producing output, analyzing that output and if it finds the word Queued followed by a number greater than 100 it sends me an email. There are a lot of spaces after queued but I believe my code is correct to accommodate for those. Currently I am only receiving an email when the number is set to 0. Any other number set by -gt or -ge is not notifying me when it should.

Script -

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

[int]$Queued = (Select-String -Path $Output -Pattern '(?<=Queued:\s+)\d+').Matches.Value

if ($Queued -ge 100)

This is the output it's analyzing - Summary of jobs on usclwnbma01

Queued:                                130
Waiting-to-Retry:                        0
Active:                         124
Successful:                   26913
Partially Successful:           114
Failed:                         186
Incomplete:                       0
Suspended:                        0
Total:                        27337
2
  • 1
    What happened since 6 hours ago when it was working ? Commented May 19, 2018 at 1:44
  • Evidently false alarm...the script was no longer giving errors but it can't seem to get past 0. I think it's having a problem translating the number or something Commented May 19, 2018 at 1:48

2 Answers 2

0

$Queued returns a collection in my tests. So this should the right approach:

 $Queued = (Select-String -Path $Output -Pattern '(?<=Queued:\s+)\d+').Matches.Value

foreach( $entry in $Queued) {
  if( [int]$entry -ge 100 ) {
    # do something
  }
} 
Sign up to request clarification or add additional context in comments.

2 Comments

Still only getting an email on 0.
Could you provide you input file for download?
-1

as mentioned in this answer

first you need to assign the casted value to a variable before using it in the if condition.

$strQueued = (Select-String -Path $Output -Pattern '(?<=Queued:\s+)\d+').Matches.Value

$Queued = [int]$strQueued

if ($Queued -ge 100)

5 Comments

Still only works with 0, any other number doesn't send an email
@AB2112, could you confirm that your regex is working correctly and returning expected output? I'm not sure if powershell supports non fixed width look behind. See details here
It's producing the file if that's what you're asking? If it doesn't support it what other options do I have?
@AB2112, see if you could echo (or its powershell equivalent) the value of $strQueued and confirm that its value is indeed 130 for the output given above
@AB2112 Try changing the regex to Queued:\s+(\d+) and change the first line to $strQueued = (Select-String -Path $Output -Pattern 'Queued:\s+(\d+)').Matches.Groups[1]

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.