Link to home
Start Free TrialLog in
Avatar of Isaias Perez
Isaias PerezFlag for United States of America

asked on

Retrieving Disabled Users from a Distribution List

I have a pretty large distribution list that has 100s of users. The old IT Team did not do a good job of managing these DLs and now the DL has dozens of users that are off boarded/disabled. So any time you send an email you get the dreaded DNR from those users. Logically I am thinking that i need to first extract unto an CSV file all current users from that DL (Samaccountname). Then I can take that data and run it through another script that will isolate all disabled users. Then take that data and run another script that will strip all AD memberships off of those users that would include that distribution list. Am I thinking of this correct logically or is there an easier method to get this accomplished?
Avatar of Isaias Perez
Isaias Perez
Flag of United States of America image

ASKER

So far i was able to get all Exchange Mailboxes that were tied to AD User Objects that are disabled/offboarded using the following PS Script.

$mailboxlist = Get-Mailbox -ResultSize Unlimited |
  ? { $_.ExchangeUserAccountControl -match “AccountDisabled” -and !$_.isLinked -and !$_.isResource }

Open in new window


I have spot checked the list and the 10 i checked did correspond to users that are disabled in AD. My next step is to delete all these mailboxes. I will probably spot check another 30-50 to make absolutely sure. But my end goal is to delete all of these mailboxes that are tied to disabled offboarded users in AD. Now i have a list of 364 mailboxes (UserPrincipalnames). Now to find a script that will take this data and remove from Exchange 2010 on prem.
Avatar of Rajkumar Duraisamy
To export the members

Get-DistributionGroupMember "GroupName" | export-csv c:\temp\GroupName.csv

Validate the users who are disabled in AD from the above output.

Get the output of disabled users alias in a csv from above command into a new csv file.. and to remove the members

Import-csv C:\temp\disabledusers.csv | foreach { remove-distributiongroupmember "grouname" -Member $_.alias }

Please ensure you have the right users in csv files
Yes but I need a way of validating which users within the Distribution List are disabled opposed to checking them 1 by 1. There should be a PS Script with logic built in that will  check each object to see if its corresponding AD User Object is disabled.
ASKER CERTIFIED SOLUTION
Avatar of Rajkumar Duraisamy
Rajkumar Duraisamy
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This is the error i am getting:  Get-ADUser : Cannot find an object with identity: 'SMoran' under: 'DC=contoso,DC=net'.

I believe that we are getting this error because the CSV File Aliases field are exchange alias not AD attriubute values.
For me Alias works.. not sure why it is not working for you..

You are able to get the information for your ID ?

Import-Module ActiveDirectory

Get-AdUser -Identity "YourSAMAccountName"
Had to run it off of a domain controller but it worked thanks.