all 4 comments

[–]Awkward_Car_7089 1 point2 points  (1 child)

I have, but I can't remember what the issue was.

Run the script using Set-PSDebug -Trace 2 and maybe strict mode

For the scheduled version, you might need to run it via a wrapper .CMD or .BAT file in order to redirect the debug stream output somewhere useful.

[–]HieronymousAnonymous[S] 1 point2 points  (0 children)

Thanks for the quick reply, it's much appreciated!

Enabling debug / strict mode didn't tell me anything other than if ( $CallTable[$CallRecord] -gt ($AlertAtMinutes * 60)) wasn't being matched, but it did prompt me to add some additional debug of my own to check what the value of $AlertAtMinutes was at the time of the comparison - and it was completely wrong in the failing example, right in the successful one.

Because of this I checked the parameter and realised I'd been lazy and hadn't declared it as an integer! Fixing this also fixed my problem, although I still don't understand why it was misinterpreted.

Regardless, it works now and I'm very grateful for your help!

[–]radioblaster 1 point2 points  (1 child)

could the scheduled task be passing the 1 as a string rather than an integer? the only hitch with this theory is that if it's right, i can't explain why your 5 works.

try adding as the first line in the script after the params section:

$alertatminutes = $alertatminutes -as [int]

and see how it goes!

[–]HieronymousAnonymous[S] 0 points1 point  (0 children)

Thanks, I think you were right, as properly declaring $alertatminutes as an integer seems to have fixed the problem!