AB2112
AB2112

Reputation: 71

PowerShell -gt comparison operator not working

I am currently using a PowerShell script to read the output of a file and then if the number is higher than I want, it sends an email. Script is below -

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

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

if ($Queued -gt 1) 

It is creating the file, but it's not sending it to me. I know my email scripts are working because they're the same ones I always use. It seems it's having a hard time interpreting the string. I do not receive any errors on the code. The output it's reading from looks like this -

Summary of jobs on usctest01
Queued:                                6
Waiting-to-Retry:                        0
Active:                           0
Successful:                   25863
Partially Successful:           113
Failed:                         184
Incomplete:                       0
Suspended:                        0
Total:                        26160

Upvotes: 2

Views: 2960

Answers (1)

Guenther Schmitz
Guenther Schmitz

Reputation: 1999

if you check out get-member on $Queued by running $Queued | gm you will see this: TypeName: System.String

so $Queued is a string and thus -gt does not work. however if you cast the the variable as integer as follows (the [int] tells the variable to be an integer) you can use -gt as shown in your example:

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

running $Queued | gm now will show you this: TypeName: System.Int32

Upvotes: 3

Related Questions