Back to blog

List all Disabled User Accounts that are still a member of Distribution Groups in Office 365

May 11, 2016 by Emma Robinson

When an employee leaves your company you will most likely disable their Office 365 user account but leave their mailbox around – so the person who is replacing them can access any pertinent historical mail.  It is also incredibly likely that this employee is the member of one of more Distribution Groups.
The last thing you want is for this person’s mailbox to fill up with emails sent to a group, so you need to make sure that you have a process to remove disabled user accounts from any distribution groups they may have been a member of.
We’ve created a script which you can download and run against your Office 365 environment. It will create a CSV file listing all disabled user accounts in your Office 365 environment that are still members of a group.
We’ve published the script over at the Microsoft Scripting Center where you can download it for free.

To run the script, simply download it to a folder and type Get-DisabledGroupMembers.ps1. 
If you get an error about PowerShell scripts being disabled on your system, you can resolve it using this fix.
When the script is run, you will be prompted to enter the Username and Password of your Office 365 Admin account and it will then go through and search for users.
Running Script
The script will then create a CSV file in the current folder with the results, which you can open in Excel.
Excel Output
If running a PowerShell script looks a little too difficult or painful, you can use Cogmotive Office 365 Reports to do the hard work for you, with just a couple of mouse clicks.
Simply browse to the Distribution Group Members report and add a filter to display only members with BlockCredential set to true.  This will return the same results as the script and they can be easily exported to a CSV file or emailed to someone.
Disabled Users Accounts in Groups Cogmotive
You can even schedule this report to be regularly emailed to the helpdesk to ensure that you stay on top of this in the long run!
If you’re not currently using Cogmotive Office 365 Reports, why not find out more here, or sign up for a free trial now?