Author Posts

December 10, 2016 at 1:40 am

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"
   }

December 10, 2016 at 7:49 am

What's line 4 meant to do?

December 10, 2016 at 8:09 am

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

December 12, 2016 at 2:31 am

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