It's a standard practice amongst most organizations one user of sleave or have been let go to disable
their associated Active Directory user account.
This allows an administrator to easily re-enable the account in the event that the user comes back to
work or if someone else needs access to the call.
Obviously this have become a common practice because the process of restoring a deleted Active Directory
a user account is a much more complex alternative.
Additionally if these user accounts are left mailbox enabled you can end up with distribution groups
that contain multiple disabled user accounts.
This video will show you how to remove these disable Tikhon's using the Exchange management shell.
So to remove disabled Active Directory user accounts from all distribution groups in the organization
we can use the following code this code to use is there foreach loop to iterate through each distribution
group in the organization as age group was processed.
We retrieve only the members whose recipient type contains the word user.
We are also filtering out all known user mailboxes as these are tied to disable to Active Directory
accounts.
These filters will ensure that we only wipe objects with Active Directory it comes down to the get to
use user command left which will determine whether or not their account is disabled by checking the
User Account Control Group or two of each object the account is disabled.
It will be removed from the group.
I would say that we have is able to use are in sales distribution group and we want to remove it for
the demonstration purposes.
Let's check my graph to count and see if it is disabled or not.
Let's type get the user Mike and we can see that the county is enabled right now.
Like let's check that Mark is a member of sales group.
We can tight get distribution group member sales.
And as you can see my graph is now a member of this distribution group.
Now that's disable Mark's account and run the following script will type disable A-Day account.
Mark the path through to see the results on our screen.
Now let's check mark secant once more my type in get to the user Mike and see that is a contest disabled
right now.
Let's switch over to our eyes see and try to this.
And Transat script.
When it is done we can double check that the script ran properly by Teigen get distribution group member
sales and find out that Mark's account was removed from this distribution group.
Now if you want to just check what users are disabled to the groups instead of Performa remove operation
we can use a slightly modified version of the previous code to simply generate a report based on disable
active directory accounts that are members of a specific distribution group.
So instead of running a remove distribution group member come on out after finding the members which
who are disabled we can ram the output of the report variable to the experts says the command left and
export the results to the specified sales file.
For example Seacole and disabled group members dunce's via.
So after running this code a report will be generated to you that the specified file name that will
list the disabled account name change recipient type and associated distribution group for reach.
It is a member.