Easily Manage Multiple Office 365 Tenants with Windows PowerShell

Eugène Dauphin

by Eugene Dauphin on 12/6/2015

Share this:

Article Details

Date Revised:

Applies to:
administration, Azure AD, Exchange Online, multiple tenants, Office 365, PowerShell, SharePoint, store credentials

When working with a lot of Office 365 customers and their tenants, it could be time consuming to connect with PowerShell to Office 365 for each customer individually over and over again. For quite some time I pasted statement by statement in a PowerShell Window and had to login multiple times. To solve this problem I wrote two PowerShell scripts to make my life easier:

One script makes it possible to store the credentials for a tenant. StoreCredentials.ps1

A second script to connect to an Office 365 tenant with the stored credentials. Connect.ps1


Before you can use these scripts, you need to have the following components installed:

How it works

Follow the steps below to easily connect to your Office 365 tenants:

  • Create a folder to store the PowerShell scripts, for example D:\WorkDir\Office365.
  • Open (Windows Azure Active Directory Module for) Windows PowerShell as Administrator.
  • Run the StoreCredential.ps1 script and specify the tenant folder to store the credentials for each tenant. Note: If the folder does not exist, it will create the folder next to the script.

Use a PowerShell script to create a new folder in an Office 365 tenant Easily Connect to Office 365 PowerShell – Create a new tenant (folder)

In some cases, you might need to update the password file because the password of the user has expired. In that case, provide the –Force parameter to the StoreCredentials.ps1 script.

Use the – Force parameter to force the password update for tenant (folder) Easily Connect to Office 365 PowerShell – Force password update for tenant (folder)

  • Run the Connect.ps1 script and specify the tenant folder.

Run the Connect.ps1 script and specify the tenant folder to connect to Easily Connect to Office 365 PowerShell – Connect to an existing tenant

After running the Connect.ps1 script, you can manage:

  • Azure Active Directory
  • Exchange Online
  • SharePoint Online
  • Office 365 PnP PowerShell Cmdlets

If you want to use these scripts in a migration scenario, you manually need to enter the on-premises credentials. I hope that these scripts will make your life easier as well, feel free to comment. You can download the scripts below or visit the GitHub repository.

Office 365 PnP PowerShell Cmdlets

OfficeDev PnP Cmdlets is part of the community-driven Office 365 Developer Patterns and Practices (PnP) program and contains a set of cmdlets specifically designed to provision and modify artifacts in SharePoint Online. In this way, they differ a bit from the PowerShell cmdlets provided by Microsoft, which are mainly focused on administrative tasks. The cmdlets utilize CSOM behind the scenes, which means that you can run them on any computer that has access to your server over HTTP / HTTPS. If you want more guidance on how to use the Cmdlets, check out this blogpost from Erwin van Hunen.


All scripts and other PowerShell references on this blog are offered “as is” with no warranty. While these scripts are tested and working in my environment, it is recommended that you test these scripts in a test environment before using in your production environment.


This article is published with permission. You can view Eugene’s original article here: http://www.eugenedauphin.com/2014/09/easily-manage-multiple-tenants-with-windows-powershell/

Topic: PowerShell

Sign in with

Or register