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:

Update 2015-10-08: Office 365 PnP PowerShell Cmdlets added

Update 2015-08-26: Force switch and directory creation added for store credentials

  • One script that makes it possible to store the credentials for a tenant.
  • A second script to connect to an Office 365 tenant with the stored credentials.

 

Prerequisites

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

  • Create a folder to store the PowerShell scripts, for example D:WorkDirOffice365.
  • 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.
  • Easily Connect to Office 365 PowerShell

    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 paramter to the StoreCredentials.ps1 script.

    Easily Connect to Office 365 PowerShell

    Easily Connect to Office 365 PowerShell – Force password update for tenant (folder)

  • Run the Connect.ps1 script and specify the tenant folder.
  • Easily Connect to Office 365 PowerShell

    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.

Disclaimer

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.