PowerShell for Office 365 administrators

Are you looking for an Office 365 administration tool to automate repetitive tasks? Or perhaps you are looking to access additional capabilities that aren't available in the Office 365 admin center? Then PowerShell for Office 365 is for you.

What is PowerShell and why use it?

PowerShell (also known as Windows PowerShell or Microsoft PowerShell) is a command-line environment that's designed specifically for system administration. PowerShell helps you control and automate the administration of the Windows operating system, server applications, and cloud-based services such as Office 365.

The most basic part of PowerShell is called a cmdlet (pronounced command-let). Cmdlets allow you to get things done in Office 365, such as adding users to your Office 365 organization, managing Office 365 license assignments, and listing which mailboxes are inactive.

You can put multiple cmdlets together into a set of commands to run all at once or you can place them in a text file to create a PowerShell script that you can run at any time. Scripts are great for periodic administrative tasks, such as creating monthly reports of licenses assigned to users or active mailboxes.

PowerShell is complementary to the Office 365 admin center

The Office 365 admin center is the out-of-box solution that spans the entire administration life cycle from setup to support. The Office 365 admin center is designed to handle the most common administration tasks like adding and editing users and changing common service settings.

However, there are situations in which PowerShell for Office 365 can save you significant time and effort. Here are some examples:

  • Adding or editing a large number of users

  • Using multiple filters to sort through data

  • Exporting data such as user lists and groups

Additionally, you must use PowerShell to configure some settings that are less-commonly used.

Getting Started

Before you start using PowerShell for Office 365, there are several things that you need to do to ensure that you can connect to your Office 365 subscription and the services that you intend to manage.

You must be an Office 365 administrator

If you are not an Office 365 administrator, you can stop here. Similar to managing your Office 365 subscription through the Office 365 admin center, you need an account that is an Office 365 administrator.

Tools to run the cmdlets or scripts

PowerShell cmdlets and scripts run in either the Windows PowerShell command prompt or the Windows PowerShell Integrated Script Environment (ISE), which is an environment for running Windows PowerShell commands and scripts. For Windows 8.1 and Windows 10, these are installed by default.

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

Get the PowerShell modules installed

To use PowerShell for your Office 365 subscription, you need to import the PowerShell modules for the Office 365 workloads that you need to manage.

Connect to your subscription and manage users, groups, and licenses

To connect to your Office 365 subscription and manage users, groups, and licenses, see Connect to Office 365 PowerShell.

For user, group, and license management scenarios, see User management scenarios for Office 365 PowerShell.

For additional articles to manage users, groups, and licenses, see Manage user accounts and licenses with Office 365 PowerShell.

Manage SharePoint Online

To manage SharePoint Online sites, permissions, and groups, download the SharePoint Online Module.

For SharePoint Online site collection scenarios with PowerShell, see More functionality scenarios for Office 365 PowerShell.

For additional articles to manage SharePoint Online sites, permissions, and groups with PowerShell, see Office 365 PowerShell for SharePoint Online.

Manage Skype for Business Online

To manage Skype for Business Online policies, download the Skype for Business Online Module.

For Skype for Business Online policy scenarios with PowerShell, see More functionality scenarios for Office 365 PowerShell.

For addditional articles to manage Skype for Business Online policies with PowerShell, see Manage Skype for Business Online with Office 365 PowerShell.

Manage Exchange 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.

For additional articles to manage Exchange Online with PowerShell, see Using PowerShell with Exchange Online.

How to run a block of PowerShell commands

In many cases, articles provide you a set of PowerShell commands to run as a block. You can run these command blocks in the following ways:

  • Copy the commands from the article or web page and paste them into Notepad (or another text editor of your choice). Make the needed changes, such as specifying account names, in Notepad. To run them, copy the completed commands in Notepad and paste them into the PowerShell command prompt on your computer.

  • Copy the commands from the article or web page and paste them into the PowerShell ISE on your computer and make the needed changes. Highlight the commands as a block and then run them.

Where possible, we try to simplify the process of getting something done with PowerShell by using variables.

The lines of a command block that start with the “$” character are variables for a setting that you need to specify. After you have specified all the settings for a command block, essentially by filling-in-the-blanks, you can run them.

How to run a PowerShell script

In some cases, you'll find a PowerShell script to run that automates an Office 365 administrative task. To run PowerShell scripts, you need to do the following:

  1. Configure PowerShell to run scripts.

    Because running a malicious script can potentially harm your computer, the default setting for PowerShell is to not run them. You will need to change the execution policy of your computer to be less restrictive. See User management scenarios for Office 365 PowerShell for more information. You only need to do this once for each computer on which you are running PowerShell scripts.

  2. Store the script file somewhere.

    Script files have a .ps1 extension. Download them to a location on your local disk drive that you can reference when you run them. For example, create a folder on your C: drive named PSScripts (C:\PSScripts).

  3. Modify the script (as needed).

    Some scripts may require you to specify custom settings, such as substituting your domain name so that it works with your Office 365 subscription.

  4. Run the script.

    Connect to the appropriate Office 365 workload that you are managing (as needed), and then run the script within the PowerShell command prompt or ISE by referencing the PowerShell script name (the file name with the .ps1) and its location. You may get a warning for scripts that are not digitally signed.

See Also

Office 365 PowerShell scenarios

Why you need to use Office 365 PowerShell

Getting started with Office 365 PowerShell

Office 365 PowerShell community resources

Connect with an expert
Contact us
Expand your skills
Explore training

Was this information helpful?

Thank you for your feedback!

Thank you for your feedback! It sounds like it might be helpful to connect you to one of our Office support agents.

×