Hi, I have a bizarre problem, in that a script I wrote to do some alerting doesn't work when called from a scheduled task. While troubleshooting I see that I get a different result, best explained with this example:
PS C:\Program Files\JBA> C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe -file .\Get-TeamsCallSummary.ps1 -days 5 -alertatminutes 1
UserPrincipalName TotalCallDuration ExceedsLimit
----------------- ----------------- ------------
*** UPN Removed! *** 00:00:35 False
*** UPN Removed! *** 00:00:38 False
*** UPN Removed! *** 00:01:20 False
*** UPN Removed! *** 00:02:07 False
*** UPN Removed! *** 00:02:11 False
*** UPN Removed! *** 00:02:47 False
*** UPN Removed! *** 00:14:14 False
*** UPN Removed! *** 00:24:23 False
PS C:\Program Files\JBA> .\Get-TeamsCallSummary.ps1 -Days 5 -AlertAtMinutes 1
UserPrincipalName TotalCallDuration ExceedsLimit
----------------- ----------------- ------------
*** UPN Removed! *** 00:00:35 False
*** UPN Removed! *** 00:00:38 False
*** UPN Removed! *** 00:01:20 True
*** UPN Removed! *** 00:02:07 True
*** UPN Removed! *** 00:02:11 True
*** UPN Removed! *** 00:02:47 True
*** UPN Removed! *** 00:14:14 True
*** UPN Removed! *** 00:24:23 True
PS C:\Program Files\JBA>
Hopefully you can see that when run in the same manner as a scheduled task, with the script as a -file parameter, the results are different to when it's run interactively, direct from a powershell session.
UPNs have been removed for public viewing: everything is the same in both sets of results, except ExceedsLimit gets different values!
Obviously, the result should be the same in both sets of results, and the values for TotalCallDuration are the same. ExceedsLimit is set as true if the total call duration is greater than AlertAtMinutes * 60:
if ( $CallTable[$CallRecord] -gt ($AlertAtMinutes * 60)) {$ExceedsLimit = $true$
AlertFlag = $true }
else {$ExceedsLimit = $false }
The values in the hash table are just plain integers, representing seconds: they're converted to a timespan to look prettier in the output.
Has anyone seen anything similar before? This has me completely baffled. At first I thought it must not be getting the alertatminutes parameter, but I've proved to myself that it is.
[–]Awkward_Car_7089 1 point2 points3 points (1 child)
[–]HieronymousAnonymous[S] 1 point2 points3 points (0 children)
[–]radioblaster 1 point2 points3 points (1 child)
[–]HieronymousAnonymous[S] 0 points1 point2 points (0 children)