Isaias Perez
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?
To export the members
Get-DistributionGroupMembe r "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-distributiongroupme mber "grouname" -Member $_.alias }
Please ensure you have the right users in csv files
Get-DistributionGroupMembe
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-distributiongroupme
Please ensure you have the right users in csv files
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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"
You are able to get the information for your ID ?
Import-Module ActiveDirectory
Get-AdUser -Identity "YourSAMAccountName"
ASKER
Had to run it off of a domain controller but it worked thanks.
ASKER
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.