Office 365 PowerShell – Part 2

In the previous article of this series, I described how to prepare our environment with all the necessary software needed to connect to Office 365. We installed the following software:

  • Microsoft Online Services Sign-In Assistant
  • Azure Active Directory Connect
  • Azure Active Directory PowerShell

After successfully installing, we connected to the cloud services using the following command:

Connect-MsolService -Credential (Get-Credential)

After that, we ran a few more commands to confirm that the PowerShell commands are being ran and executed. In this article, we will continue to connect to different services and explain the specifics, that each of these brings. The first of these services is Skype for Business.

Skype for Business

To manage Skype for Business, we require a special PowerShell module, which can be downloaded from the following address:
Download Skype for BusinessOnline, Windows PowerShell Module from Official Microsoft Download Center

After successfully installing the software, we can open our preffered PowerShell scripting tool and connect to Skype for Business in the cloud. If you use Multi-Factor Authentication for your Office 365 admins or users, running the following command will return an error, as seen in the image below.

#without MFA
$Skype=New-CsOnlineSession -Credential $cred

If MFA is enabled, we must run the command without the psCredential object, as follows:

#MFA enabled

After successfully signing in with our preffered MFA authentication method, we can run the following commands, which will enable us to manage Skype for Business:

#importing session into PowerShell
Import-PSSession $Skype

Available Commands

To get a list of available commands, we need to perform a small workaround. After we perform the Import-PSSession, the module name is temporarily shown in the PowerShell window.

We can then use this name to list available commands in the following way:

#list Skype for Business commands
Get-Command -Module tmp_b03cx2m5.dbc

If we add the count method, we will see the number 277, which means that the session import enables us to use 277 command to manage Skype for Business online.

As a helpful tip, I can tell you that all commands for Skype for Business online start with “CS”. For example, to list all users, you can use:

#list users

Ending the Session

In Exchange Online and Skype for Business it is very important to end the sessions after we finish managing the service. In PowerShell, we use the following command:


Of course, we must also speify which session we want to end. At the beginning, we saved our session into the “$Skype” variable, which then use in the command:

#ending the session
Remove-PSSession $Skype

After successfully executing this step, our session is finished and all commands for managing Skype for Business online disappear.

Be sure to check out part 3 of this article series.

Robi Vončina

Author: Robi Vončina

Office Servers and Services MVP, MCT

Leave a Reply

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