Thursday, July 3, 2014

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
$lyncSession = New-CsOnlineSession -Credential $O365cred

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 "" -Credential $O365cred -Authentication Basic -AllowRedirection

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:

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

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:

When you want to end your management session, make sure that you close both remote sessions:
Remove-PSSession $lyncSession
Remove-PSSession $exchangeSession

No comments:

Post a Comment