Step 7: End Your Windows PowerShell Session

 

You might be wondering why we even bothered to include this step. After all, how hard can it be to end a Windows PowerShell session: you just close the PowerShell window and everything disappears. Case closed.

And that’s true: everything will disappear. However, that doesn’t necessarily mean that your remote sessions have been properly disposed of. For example, even if you close the PowerShell window your Lync Online remote connection will remain active for the next 15 minutes or so. That could prove to be a problem. Why? Because Lync Online limits the number of simultaneous connections that any one person or any one domain can have open. With Lync Online, an individual administrator can have, at most, three open connections at one time, while a domain can have a maximum of nine open connections. If you log on to Lync Online and then exit without properly closing the session, that session remains open for the next 15 minutes or so. As a result, that’s one fewer connection available to you or to other administrators in your domain.

Which means that this time the kids are right: having more available connections is better than having less available connections. In turn, that means that it’s a good idea to close your sessions once you’re done with them.

To start with, let’s close the remote sessions opened for Lync Online and Exchange Online. Before we do that, run this command:

Get-PSSession

The Get-PSSession cmdlet should show you that you have at least two remote sessions open, one for Lync and one for Exchange (it’s possible you could have more than two remote sessions running, depending on whether you’ve used this instance of PowerShell to connect to something else besides Office 365). At any rate, you should see something similar to the following:

Id Name     ComputerName    State   ConfigurationName    Availability
-- ----     ------------    -----   -----------------    ------------
 2 Session2 webdir0a.onl... Opened  Microsoft.PowerShell Available
 3 Session3 pod51035psh.... Opened  Microsoft.Exchange   Available

To close these two sessions, use these commands, the first to close Lync, and the second to close Exchange:

Remove-PSSession $lyncSession
Remove-PSSession $exchangeSession

If you now run the Get-PSSession cmdlet you should see nothing at all (unless, of course, you have other remote sessions up and running):

Windows PowerShell console with no remote sessions

Note

If you’d prefer to close all your remote sessions at the same time, you can use this command:
Get-PSSession | Remove-PSSession

If you now try running a Lync Online or an Exchange Online cmdlet (for example, Get-CsMeetingConfiguration) you should get this error message:

Get-CsMeetingConfiguration : The term 'Get-CsMeetingConfiguration' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

We get that error message because the Lync Online and the Exchange Online cmdlets were deleted when we closed the remote sessions.

To close the SharePoint Online session, type this command:

Disconnect-SPOService

Again, it won’t look like anything has happened. But if you try to run the Get-SPOSite cmdlet you’ll get this error message:

get-sposite : No connection available. Use Connect-SPOService before running this CmdLet.

You can’t retrieve site information because you’re no longer connected to SharePoint Online.

As for your connection to Office 365 itself, well, although there’s a Connect-MsolService cmdlet there’s no corresponding Disconnect-MsolService cmdlet. So, in that case, you will just have to close the Windows PowerShell window. Nevertheless, it’s still a good idea to properly disconnect from SharePoint, Lync, and Exchange.

See Also

Connect to Office 365 by using a single Windows PowerShell window