fbpx

Blog

Back

Connecting to Office 365 using Powershell

30 May 2012 by Emma Robinson

We have updated this blog, click here to read the most up to date version. 
The most powerful way to manage Office 365 is by using PowerShell, a command line interface that connects to Office 365 via the Internet.
Whilst it may seem daunting to people unfamiliar with working on the Command Line, it really isn’t as hard as it looks. This blog post will guide you through the basics of connecting to PowerShell.

Set up your computer to use Powershell

Firstly, you need to set up your computer to be able to use Powershell. This only needs to be done the first time and involves downloading some tools from the Microsoft website.
Here is a link to the tools you will need to install:
http://technet.microsoft.com/en-us/library/jj151815.aspx

Start the Powershell command line

Now that you have the tools installed, you can go ahead and open Powershell. The easiest way to do this is to press the start button and simply type powershell

Powershell in Start Menu

Powershell in Start Menu


You will now see a Powershell window, and the fun can begin!

Using Powershell

Now that you have a Powershell Window open, you can connect to Microsoft Office 365.
Firstly, you need to create a connection to Office 365. You can do this by typing (or copying/pasting) the following into Powershell.
Note: To paste into Powershell you use Right Click. Here is a great video on how to use Copy and Paste in Powershell

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

Once this is in the Powershell window, press Enter to execute the command.
If you get an error message telling you that execution of scripts is disabled, you can resolve that using these steps.

Connecting to Office 365 using Powershell


Now you simply type in the username and password for an Administrator account in your Office 365 and click OK.
You will probably see some warnings.  Don’t worry, they are normal.
You are now authenticated into Office 365. The last step is to connect up to Office 365 by using the following Powershell command:

Import-PSSession $session

Congratulations! You’re connected!

Now you’ve gone to all the trouble of connecting to Powershell, let’s do something to prove that it works. Type the following into the Powershell window and press Enter:

get-mailbox

You should now see a list of all the users in your Office 365 account that have mailboxes!

If you found this blog post useful, and want to refer to it again, why not download it as a PDF?

Related Posts

These other blog posts may be of interest to you:

whois: Andy White Freelance WordPress Developer London