PowerShell scripts

Top Office 365 PowerShell scripts and how to use them 

PowerShell is a powerful management tool that complements Microsoft 365 admin center.

Almost anything you can do manually in the Microsoft 365 admin centers using the browser can also be performed by writing your PowerShell scripts.

Why use PowerShell scripts?

There are numerous advantages of writing your own scripts over using the built-in Admin centers: 

  • When you have a common repetitive task, which involves a lot of clicking, you can speed it up by scripting a solution.
  • Microsoft 365 is continuously delivering new features. Often, those new features and more advanced granular configuration can only be set up using PowerShell scripts.
  • Doing bulk actions is much more time effective using scripts. 
  • Doing work on a schedule is more effective using scripts in combination with the Windows Scheduled Tasks.
  • PowerShell is considered a more documented and reliable way of changing your tenant configuration, as the Admin center’s interface changes more often than the underlying PowerShell commands.

As you can see, there are many benefits of using PowerShell to manage your Microsoft 365 tenant. There is a steep learning curve to start using PowerShell scripts, and it will take some time, but once you are accustomed to it, the payoff will be significant.

How to use PowerShell scripts to manage Microsoft 365?

Unfortunately, as it is with the Microsoft 365 admin centers, there is no central module to manage the entire Microsoft 365 at once. You will need to use the different modules to handle different workloads like Azure AD, Exchange, SharePoint Online, etc. Those modules have a different way of connecting and managing each service.

Here are the links to the most important PowerShell modules to get you started: 

  • Azure AD Module – here is information on how to manage Azure AD using PowerShell and how to get started.
  • Exchange Online PowerShell – find more information about Exchange Online and how to get started.
  • SharePoint Online PowerShell – here is a cmdlet reference for SharePoint Online and details on getting started.
  • Skype for Business Online PowerShell – cmdlet reference for Skype for Business Online and Microsoft Teams. See information on how to get started.
  • Security & Compliance Center PowerShell – manage features that are available in the Security & Compliance Center. See details on how to get started.

All this might seem overwhelming to learn, but remember, you need to solve one task at a time. The good thing is that there is a fantastic community out there and a lot of script examples, so it is very likely you won’t have to start from scratch. One of the best examples is the PnP PowerShell library, which allows you to perform complex provisioning and artifact management actions against SharePoint Online. 

We searched the whole Internet to find the most popular community scripts to help you manage your Microsoft 365 tenant. Be sure to check them out to see how many possibilities PowerShell scripting offers you to speed up your job.

Office 365 PowerShell scripts

Top 5 Office 365 PowerShell scripts

Here are the top 5 most popular scripting solutions to help you manage your Microsoft 365 environment.

1. Use the PnP provisioning engine with the PnP PowerShell module

PnP PowerShell module is an open-source community-driven effort with many contributions from MCM/MVP Erwin van Hunan. You can find it in the PowerShell Gallery with hundreds of thousands of downloads. The two most popular cmdlets in that module are related to the PnP Provisioning Engine, which allows you to create site templates to customize out of the box SharePoint sites to suit your business needs better.

Check out Erwin’s blog to find out how to write scripts to create site templates and later apply them to other sites.

2. Configure your tenant with Microsoft 365 Desired State Configuration (DSC)

Microsoft365DSC is an open-source initiative, lead by a team of Microsoft engineers and maintained by the community. It can help you automate your tenant deployment and ensures the monitoring of the defined configuration, notifying, and acting on detected configuration drifts. You can use it to extract the entire tenant configuration. Check out how to use Microsoft365DSC in the blog by Nick Charlebois, the Principal Lead of this project.

3. Finding obsolete Office 365 Groups with PowerShell

COVID-19 has forced many companies worldwide to switch to remote work overnight. This has caused a massive spike in the adoption of Microsoft Teams. In most cases, this happened so fast that there was no time to implement proper Microsoft Teams governance, leaving admins to struggle with the sprawl of new teams.

This script by Tony Redmond is an excellent example of how powerful PowerShell scripts can be. It will search your entire tenant and search for unused Microsoft 365 Groups and Microsoft Teams. Although this might seem like an easy task, in reality, it involves a lot of work. You have to manually check each group for SharePoint activity, Exchange activity, Teams activity, and connect all this data into a useful report.

If you want to create a flow for Team owners to confirm whether their teams can be safely deleted or archived, check out the Lifecycle Automation options inside Syskit Point.

4. Export all distribution Group and All members

A script from MVP Satheshwaran Manoharan helps you export all the Distribution groups and all their members to a CSV file or displays them in the Exchange Management Shell. The script also supports dynamic Distribution groups. This script was very popular on the soon to be retired TechNet Gallery with over 77 thousand downloads. Luckily the script is still available on GitHub.

If you require this report in other formats like PDF or Excel, or you need to schedule automated delivery to email, check out how Syskit Point’s Office 365 reporting can help you.

5. Export last logon time, licenses, and additional details

This is another popular script from TechNet Gallery from Nobel K Varghese. This script returns the Microsoft Graph API reports on LastActivityDetails of users for Office 365 services like Exchange Online, SharePoint Online, OneDrive for Business, etc. With this data, you can correlate which users have a license for which service and see if they have been actively using that service. The script has been moved to GitHub as TechNet Gallery will be retired.


To become a time-efficient Microsoft 365 administrator, learning how to use PowerShell scripts is a necessity. It can speed up or even completely automate many of the tasks admins must deal with in their everyday work. To master PowerShell is no easy task, and the learning curve is steep to get you started. It is always good to look for similar examples and not reinvent the wheel since thousands of examples are already available, thanks to the live Microsoft 365 community.

In the meantime, please subscribe to our newsletter below to get our PowerShell scripts, among other helpful content.

Subscribe to our Newsletter

Related Posts