Get Started

Before you start using PowerShell for Office 365, there are several things that you need to do before you can connect to your Office 365 environment. 

Are you an admin? Do you have the tools?

You must be an Office 365 administrator

If you are not an Office 365 administrator, you can stop here. Similar to accessing your Office 365 organization through the Office 365 admin center, you need your Office 365 admin credentials.

Tools to call the cmdlets or scripts

PowerShell cmdlets and scripts run in either the Windows PowerShell environment or Windows PowerShell ISE, which is a pseudo-graphical environment for Windows PowerShell. For Windows 8.1, these applications are pre-loaded.

With either application, you now have the tools to administer Office 365 using PowerShell.

One thing to note though, with either application, you need to run them as an administrator. To do this, you simply need to right click on the app and select Run as administrator.

Get the PowerShell modules.

To connect to your Office 365 environment, you need to import the PowerShell modules for all the relevant Office 365 workloads.

  • Azure Active Directory Module (for Office 365)
  • SharePoint Online
  • Skype for Business Online

The cmdlets for administering Exchange Online are not in modules that you can download and import. They are only available when you create a remote connection to Exchange Online. Once you connect or "remote" into these services, you import the cmdlets from there.

If If this is the first time you are using PowerShell on your PC, it is likely that your PC is not setup to connect with Office 365 using PowerShell. Please follow the following steps to setup your PC.

  1. Download Microsoft Online Services Sign-in Assistant to sign into Office 365.
  2. Download Azure Active Directory (AD) Module so that you can perform administrative tasks in Office 365.
  3. Download SharePoint Online Module so that you can manage SharePoint Online.
  4. Download Skype for Business Online Module so that you can manage Skype for Business Online.

After installing the modules, you can now start using PowerShell for Office 365.

The first step in using PowerShell for Office 365 is connecting to your Office 365 organization and then import the relevant modules. Plesae refer to the scenario, Connect to Office 365 Cloud Services using PowerShell to start connecting to your Office 365 environement and all your relevant office 365 services.

Some things to note before you start.

Scenarios and sample scripts

To help you get started in PowerShell, a selection of common scenarios and sample scripts have been provided.

Each scenario may contain several sample scripts that you can run in your Office 365 environment. Some of the sample scripts may require modifications such as substituting your domain name so that it works with your Office 365 environment.

The sample scripts can be downloaded or copied right off the website and edited in Notepad or PowerShell ISE. Please note that if you download the sample scripts, they are not digitally signed so you may get a warning.

Check the execution policy of your PC

By default, it is likely that your PC is setup to not run scripts as scripts can potentially harm your computer.

For you to run the PowerShell scripts from this site, you will need to change the execution policy of your device to a policy that is less restrictive so that you can run the scripts. Refer to this scenario, Setting execution policies on Windows PowerShell.

Please note that if you are using the execution policty: RemoteSigned, you will need to edit the script and save it prior to executing.

To learn more, please go here.


Office Mechanics: PowerShell basics for managing Office 365 and the space race

Jeremy Chapman and Greg Stemp introduce PowerShell for managing Office 365. Jeremy and Greg explain when PowerShell makes sense compared to the user interface and describe the basics of how PowerShell works.

Office Mechanics: Learn PowerShell basics for managing Office 365 - Part 2:

Jeremy Chapman and Greg Stemp apply PowerShell to practical tasks within Office 365 including automating bulk tasks, building advanced queries against data in the service and things you just can't do in the user interface.