Wednesday, August 27, 2014

How to Connect to Office 365


In this post, I am going to simply discuss how to connect to Office 365 using Powershell.  With Powershell, you can manage and automate several tasks in Office 365, which will make your life much easier.  Some of the tasks I have automated are user account creation, distribution group memberships, and licensing.  I will outline connecting to Microsoft Online, where you can manage items such as accounts and licensing.  I will also cover how to connect to Exchange Online, which is more directed at mailbox related tasks.

Required Components

Before connecting, you'll need to install 2 components on your PC: the Microsoft Online (MSOL) Sign in Assistant, and the Azure Active Directory Module.  Keep in mind, the MSOL Sign in Assistant must be installed before you can install the Azure AD Module.  Here is where these can be obtained:


MSOL Sign in Assistant
Azure AD Module



Making the Connection

After you have finished installing the required components, open a new Powershell session.  The first thing we are going to do is import the MSOL module.


 import-module msonline  

Next, we need to initiate the connection.


 connect-msolservice  

You will be prompted for your Office 365 administrator login credentials.



Connecting to Exchange Online

Again, Exchange Online is useful for more mailbox related functions.  If you need to add a user to a distribution group, this is where you'll turn.  First, we need to capture the administrator credentials for your Exchange Online domain.  You will be prompted for your username and password.


 $credential = get-credential  


Next, lets store the session cmdlet in a variable called $Session.


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

Now, we initiate the session.


 Import-PSSession $Session  

When you're finished with your session, it's a good idea to disconnect gracefully.  I'm not sure what the default connection time-window is for Exchange Online, but I do know there is a small limit to the number of simultaneous connections you can have open for your domain.  If you have to many sessions open that you didn't disconnect, you won't be able to reconnect for a duration of time.  Here's how to disconnect:


 remove-pssession $Session  


That's all there is to connecting to Office 365.  I hope to add more posts centered around Office 365 in the near future that will show you how perform everyday tasks and setup some automation.

No comments:

Post a Comment