Notify on Threshold Exceeded

Welcome Forums General PowerShell Q&A Notify on Threshold Exceeded

This topic contains 3 replies, has 3 voices, and was last updated by

Hil
 
Participant
2 years, 3 months ago.

  • Author
    Posts
  • #59946
    Hil

    Participant
    Points: 23
    Rank: Member

    Hi,
    I have a script that will Notify when a threshold value is exceeded. I have most of the code of the code in place , except the threshold part does not render logically correct.
    I have placed below the part of the code giving me a problem. I am not sure why it says 7 is greater than 10.
    Please help. Thanks

    $MaxQueueCount = 10
    $FileQueueCount  = "c:\Logs\QueueCount.txt"
    $var = 7
    $var > $FileQueueCount
    $QueueCount = Get-Content -path $FileQueueCount
    write-output "QueueCount = $QueueCount"
    
    If ($QueueCount -ge $MaxQueueCount) 
       {
        $Notify = 1
        write-output "$QueueCount is greater than $MaxQueueCount"
       }
    
  • #59950

    Keymaster
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    What's line 4 meant to do?

  • #59952

    Participant
    Points: 1,166
    Helping Hand
    Rank: Community Hero

    You're comparing a string with an integer. That always produces confusing.
    First you set $MaxQueueCount to 10 – that's an integer. Then you fill $FileQueueCount with the path to a file. Then you set $var to 7 – that's an integer either – yet. Then you write this integer to the file the path you stored before in $FileQueueCount. Now you fill in $QueueCount with the text (string) of this file. After you showed the content of the variable $QueueCount on the console you compare then the content of the variable $QueueCount, what's still a string, with the content of the variable $MaxQueueCount – what's an integer. If I'm not wrong has 7 the ASCII code 55 – so it's greater than or equal to 10. 😉

    To correct your code and produce the result you probably expect you can do either this

    $QueueCount = [INT](Get-Content -path $FileQueueCount)

    or this

    [INT]$QueueCount = Get-Content -path $FileQueueCount
  • #59970
    Hil

    Participant
    Points: 23
    Rank: Member

    Thanks Olaf. You are the man !!!!
    That fixed it

The topic ‘Notify on Threshold Exceeded’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort