Managing Lync Online and Exchange Online from the same PowerShell session

When working with Office 365, administrators often need to resort to PowerShell in order to perform certain configuration tasks or reporting. One “issue” is that Lync Online and Exchange Online do not share the same URI, nor do they use the same connection method. This implies that administrators need to use separate sessions to manage both Lync and Exchange Online.

But is this really true? No! It is perfectly possible to manage both products from the same instance of PowerShell. To begin with, start PowerShell and connect to Lync Online (remember that you will need Windows PowerShell Module for Lync Online):

$O365cred = Get-Credential [email protected]

$lyncSession = New-CsOnlineSession -Credential $O365cred

Image

Next, use a similar process to connect to Exchange Online (you do not need to create a new Credentials object):

$exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $O365cred -Authentication Basic -AllowRedirection

Image

At this point, you should have two separate remote sessions running on your computer. To verify this, type the following command at the PowerShell prompt: Get-PSSession

Image

You now have a pair of remote sessions that can be imported into your local session of Windows PowerShell. To do that, run these two commands:

Import-PSSession $lyncSession

Import-PSSession $exchangeSession

Image

At this point, you will have both the Lync Online and the Exchange Online cmdlets available for use. To verify this, use the Get-CsOnlineUser and the Get-Mailbox cmdlets, for example, and make sure that you get back user information:

Image

When you want to end your management session, make sure that you close both remote sessions:

Remove-PSSession $lyncSession

Remove-PSSession $exchangeSession

Image

About The Author

Leave a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top