Connecting to Office 365 using Powershell
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 are the tools you will need to install.
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.
You will now see a Powershell window, and the fun can begin!
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.
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:
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:
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?
These other blog posts may be of interest to you:
- Accessing Office 365 using PowerShell through a Proxy Server
- Office 365 Administrator Account Best Practises – Ensure your Office 365 account is secured
- Finding Inactive Users in Office 365 – Users that have not logged on for a certain period of time.