Link to home
Start Free TrialLog in
Avatar of DRRAM
DRRAM

asked on

Distribution Lists

Hello,

Powershell Script to Remove list of Users from all Distribution Lists
Please, I need a script (Powershell or vbs), I can use it to remove a list of users (csv file) from all of distribution lists they are a part of.

Thanks for all your help.
Avatar of DRRAM
DRRAM

ASKER

Please, I am waiting for your help
SOLUTION
Avatar of J0rtIT
J0rtIT
Flag of Venezuela, Bolivarian Republic of 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
Avatar of DRRAM

ASKER

No beacause, I need to remove a list of users (csv file) from all of distribution lists they are a part of.

Indeed, several users have different distribution lists
after we run the script the users didn't have any distribution lists.

Best regards,
Ok but give the whole information then.
What is the content of the csv? post a dummy file at least.

So you can have what you want.
Does it contain the name and last name, the samaccountname, or the display name?
What are the fields in your csv.

Jose.
Avatar of DRRAM

ASKER

Yes , excuse me

File.csv contain just the sAMAccountName

for exemple :
sAMAccountName
User1
User2
User3
User4
...

Thx
ASKER CERTIFIED SOLUTION
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
Avatar of DRRAM

ASKER

Thanks,
Please what is technical requirements to run the script

We can specify in the script the name of Domain controler and the path : ou=Site,DC=domain,DC=com

Best regards,
Just run it.
In the page is how to run it.

1. Set-executionpolicy unrestricted
2. Scriptname.Ps1-csvpath input.Csv. For samaccountname.

You're asking to run the script across an organizational unit and a domain controller this doesn't have any sense since your samaccountname is unique in the domain and those parameters are not useful for your purpose
Avatar of DRRAM

ASKER

Please Jose Gabriel;

I need this "We can specify in the script the name of Domain controler and the path : ou=Site,DC=domain,DC=com"
because when I run the script we have the followinf warning :

WARNING: By default, only the first 1000 items are returned. Use the ResultSize
 parameter to specify the number of items returned. To return all items,
specify "-ResultSize Unlimited". Be aware that, depending on the actual number
of items, returning all items can take a long time and consume a large amount
of memory. Also, we don't recommend storing the results in a variable. Instead,
 pipe the results to another task or script to perform batch changes.


Best regards,
Rami.
OK, my answer is there, they use samaccountname that you provided in the CSV.
you didn't specify the number of the enterprise so I assumed that it was small.
I'll do the changes in my script related to the number of users that can return.

Once again, if you have the samaccountname, you don't need to specify the OU, the command is intelligent enough to search the samaccountname, and relative to the domain controller and assuming is a single domain controller, not multiple domain controllers, this will be my final answer.

Update:
You have all the SamAccountName in a CSV file, there's no need at all to use the  "-resultsize  -Unlimited" because the script is taking the SamAccountName, to find out the Display Name and then use the displayName to remove the users from all the Distribution Lists (one by one). So if your csv is well structured there's no need to do anything else.  That's all from my part in this question.
The only thing saving in a variable is the Group Name and the Name. The  posted script is free and you can change it if you think it doesn't fit what you want
Avatar of DRRAM

ASKER

Thanks Jose and sorry if I bother you; I understood and I agree with you

Another way, "distribution list in exchange = distribution group in active directory"

We can remove list of users (csv file) from all of distribution group they are a members in active directory. Indeed, several users are member of different distribution group

If you want, I create another ticket for this request

Best regards,
There are 2 kinds of "groups" in AD, Security groups and Distribution Groups (the distribution groups, universal) are the one that uses exchange as "distribution group" and nope, this will only work on distribution groups on exchange server.

There are 3 scopes for "security" or "distribution" groups in AD, if you pick global or domain local, you won't see it on exchange. so Distribution group in AD != Distribution group in Exchange.

Jose.
Avatar of DRRAM

ASKER

Thx