PowerShell -gt comparison operator not working

后端 未结 1 1935
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-12 01:05

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 -

$Ou         


        
相关标签:
1条回答
  • 2020-12-12 01:47

    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

    0 讨论(0)
提交回复
热议问题