March 2, 2019

Office 365 Scripts




Let's get into our favorite Office 365 Powershell scripts.

I am going to refer to our good friends at Microsoft here as they have the best gallery of O365 Powershell scripts for admins and engineers alike.

https://gallery.technet.microsoft.com/office365 (I have this bookmarked).

NB: If you do download any of these, I do recommend you test them in a test environment first and not the production environment (just best practice caution).

Also if you do benefit from any script below, please make sure you give back to the Microsoft community by giving the script a rating. Thank you for all those who contribute powershell scripts to the MS community. Many of these scripts are written by well known Microsoft MVP's. How many do you recognize?

1: Office 365 reporting tool

This is the godfather of all scripts. It is a super script that generates 600+ GUI reports. All configurable to your discretion. If you would like to have a full birds eye view of your O365 environment including Azure, this script is will provide high level down to mailbox level reporting. Below are some of the reports you can generate with this tool.

Supported Services:

  • Azure Active Directory (43 reports) 
  • Security Reports (22 Reports)
  • Exchange Online (99 reports) 
  • SharePoint Online (35 reports) 
  • OneDrive for Business  (11 reports) 
  • Skype for Business (22 reports) 
  • Yammer (20 reports) 
  • Microsoft Teams (16 reports) 
  • General Office 365 Reports (9 reports)
https://gallery.technet.microsoft.com/office365/Office-365-Reporting-Tool-7987b4c2 

2: Office 365 Auditing report tool

Another powerful GUI report all segregated into the different O365 apps.

  •  Azure Active Directory (66 reports)
  •  Exchange Online Auditing (56 reports)
  •  SharePoint Online Auditing (57 reports)
  •  OneDrive Business Auditing (27 reports)
  •  Teams Auditing (8 reports)
  •  Power BI Auditing (23 reports)
  •  Office 365 Secure Score Reports: (62 Reports)
  •  General Auditing (12 reports)
https://gallery.technet.microsoft.com/office365/Office-365-Auditing-Tool-01747cd4


3: Get-DistributionGroupMembers.ps1

Much like its counterpart for Exchange 2010 this script will export to CSV all the Distribution Groups and its distribution group members. This can be handy when there are nested distribution groups and you want to run a report of Distribution groups that may be accessible externally (from the internet).

https://gallery.technet.microsoft.com/office365/List-all-Users-Distribution-7f2013b2 

4: MailboxSizeReport.ps1

Mailbox Size report. This report can be exported to csv and configured to display all necessary outputs. Keep checking back this one as its regularly updated with features and fixes.

https://gallery.technet.microsoft.com/office365/Mailbox-Size-Report-for-ed9435e2 

5: O365 Mail Traffic Statistics by User

This script retrieves the inbound and outbound mail traffic statistics by recipient for all available dates. It can be exported to a CSV file.

Handy when troubleshooting mailbox flow issues and possible Inbox rule interference.

Output example:

DateRecipientInboundOutboundInboundSizeOutboundSize
03/02/2014admin@cogmotive.com1093080
04/02/2014admin@cogmotive.com526993919861
04/02/2014brian@cogmotive.com0105897
04/02/2014garthf@cogmotive.com1058970


https://gallery.technet.microsoft.com/office365/Office-365-Mail-Traffic-afa37da1 

6: O365 Admin Role Groups membership report

This script produces a csv file of all the members of the admin role groups.


https://gallery.technet.microsoft.com/office365/Office-365-Role-Groups-b1eb6c6a

7: Bulk Add SMTP addresses to O365 mailboxes.

Not a usual request, however it has come up before to add additional SMTP addresses to entire firms mailboxes, or a new domain. Always a handy script to have up your sleeve.


https://gallery.technet.microsoft.com/office365/Bulk-Add-SMTP-Addresses-to-e3d28842

8: EAS troubleshooting script

Troubleshoot Exchange ActiveSync device problems. This script will collect relevant mailbox information related to Exchange Active Sync and troubleshooting areas.

https://gallery.technet.microsoft.com/office365/Exchange-ActiveSync-fb265f94

9: Generate HTML report for mailboxes

Syntax for single mailbox: 

.\Report-MailboxPermissions.ps1  -Mailbox <user@domain.com> -HTMLReport C:\Temp\<user>.html

Syntax for database:

.\Report-MailboxPermissions.ps1  -Database DB1  -HTMLReport C:\Temp\DB1.html


Syntax for all mailboxes:

.\Report-MailboxPermissions.ps1  -HTMLReport C:\Temp\ALL.html

PowerShell Scripts for your Exchange Server Toolkit