Not sure if I'm posting in the right area, but here goes.
We recently built some call queues on MS Teams and one of the requirements is to obtain real time stats on how many calls are in the queue as well as how many agents are opted in. Although this is not officially supported, it is possible by creating an online session using the SBF connector or MicrosoftTeams connect and running the Get-CSCallQueue command.
I have this working via a powershell script which outputs the results as an html files. I can tell my users to run it on demand, but it takes a couple of minutes to execute so my thought is to have it run continously (either as a service, a scheduled task, or just starting it and letting it loop using while ($true) and continually refreshing the html file which also has the auto refresh flag set.
I found some limitations in having it run as a scheduled task, so I opted to have it run as a service. What I am finding is that it can run well for several iterations, up to a day or so, but at some point it will lose the connection to the 'remote server' and simply break. Sometimes I find it prompting for credentials (the same prompt you get after the one hour timeout), sometimes it just exits with an error like 'Starting a command on the remote server failed with the following error message....'
I have tried to build in some error handling to get around these issues:
- I added commands to check the PSSession state and only run the Get-CSCallQueue commands when it is 'opened', or reconnect the session otherwise
- I simply end the session and reconnect the session at the start of each loop
- I added -erroraction continue to each get-csallqueue command in the script, my thinking is that it will simply reach the end of the loop and start over after reconnecting..
Eventually though it just fails. If the command fails and it is promting for creds I think it gets stuck there..
I think my approach to this may be all wrong, looking for ideas on how to get it to run continuously without breaking.