Hello Readers, I hope you’re well.

I hope you find this useful to know.  I know I do.

If you use the SkypeOnlineConnector PowerShell module to connect to and manage Skype for Business Online or Microsoft Teams, I have some exciting news.  First the background…

Background

The SkypeOnlineConnector is used to manage Skype for Business Online and Microsoft Teams.  If you have ever connected to it and used it, you will know there has been one annoying trait since its launch.  That is, that there is a 1 hour session timeout built in.

One minute you’ll be using it to configure Direct Routing or an Auto Attendant, then you go away for a minute or two, then run the next command, only to be asked for credentials again.

You know the one…

Creds request

And annoyingly, no matter how many times you re-enter your credentials, it won’t connect again.  That’s because the session timed out and disconnected you.

I resorted to just connecting to a new session, then importing that session using the -AllowClobber switch.

Then I wrote a PowerShell script that baked in authentication and connection in one.  My script prompts for my password and saves it to a local file as a secure string.

password out

I then pass that to a password variable that I can use to connect to my tenant.  I don’t need to worry about multiple tenants because I only manage one, my own.

Now that I have a script, I just open it in ISE and press play (Run or F5) and it runs the script, connects to a session, complete with credentials, and imports that session for use.

script

When the session times out, all I need to do is press play again and it connects to a new session and imports again.  Job done right?

What if you don’t want to have to connect to and import a new session?  There’s now a solution for that.

The Solution

Microsoft added a new function to the SkypeOnlineConnector which just needs to be used at the time of connection. Enable-CsOnlineSessionForReconnection was added, it seems, to the latest version of the SkypeOnlineConnector in October.  There is a post in Microsoft Docs for diagnosing connection problems.

enable-reconnect

Annoyingly, the SkypeOnlineConnector version is the same whether you have the latest version or the one before.  It shows as version 7.0.0.0 before and after you update it.

The new version of Skype for Business Online, Windows PowerShell Module (2046.123) is here.  Simply close any connections you have and download the exe from the link above and double click to install it.  This is the only way to update it since it wasn’t installed using install-module like most other connectors for O365.

Now open up PowerShell or ISE and run get-command Enable-CsOnlineSessionForReconnection and you should see the following…

get-command

And if you want to see the detail of the function you can get it by piping the get-command to a formatted list.  I’ll leave you to read that here or in your own session.

get-command - fl

The gist of the function is that it gets used to silently reconnect your session once it times out.

How to use it

Just add a single line to your connection script.  I’ll give you three guesses what it is…

script with reconnect

If you prefer, you can wrap it all in a function to use in your own script.

module

When you run this to connect to and import to the session and enable the session for reconnection, the function triggers when you run the first command after your session has timed out.

You’ll notice that auto complete for your SkypeOnline commands doesn’t work the way it did at first.  This is because the connection is no longer established.  What happens is that when you run the commend you get a message stating that it is “Recreating a new remote PowerShell session…” for the command you’ve run.

reconnecting

It does create the new session, and after a second, the command you ran executes and gives you the results you were after.  After that, it works just like it did before the session timed out.

It doesn’t stop the session from timing out, but it does stop you getting prompted for credentials and lets you get on with what you wanted to do.

Does it work?

I’ve been connected to a session all day and I’ve let it time out several times just to test it.  And it works a treat.  So yes!

Wrap up

Step 1 – go download and install the updated connector
Step 2 – add Enable-CsOnlineSessionForReconnection to your connection script
Step 3 – Enjoy not having to think about session timeouts

I do hope this was useful.  It is for me.