office 365 , distribution list

I have  distribution groups and there are 400 members in it, these DL's are in office 365

i need to validate how many members are there in the group
 
is there any commandshell we can run,

lets say if i want to add or remove members.

also

to run this periodically or every 15 days , how can i implement a schedule task through task scheduler.
pramod1Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

timgreen7077Exchange EngineerCommented:
Connect to O365 and run the following:

(Get-DistributionGroupMember -Identity "name of DL").count
0
MichelangeloConsultantCommented:
To complete:
Add-DistributionGroupMember -Identity yourdgroup@yourdomain.com -Member Youruser
And
Remove-distributiongroupmember

To connect to o365 you need a username/password couple so to schedule a powershell task (search on EE in case you need help on scheduling a powershell task as the question has been answered in the past) you have to save credentials in some form.
More info here:
https://docs.microsoft.com/en-us/powershell/exchange/exchange-online/connect-to-exchange-online-powershell/connect-to-exchange-online-powershell
1
pramod1Author Commented:
What about if I want to find out about members from which department they are from
0
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

Jamie McKillopIT ManagerCommented:
Get-DistributionGroupMember "Group Name" | select name,department
0
pramod1Author Commented:
I was looking at this link.

https://www.interfacett.com/blogs/using-powershell-to-report-on-distribution-group-membership-in-exchange-server/

is this same what you wrote above

how can I create a ps1 script and run through task scheduler?
0
Jamie McKillopIT ManagerCommented:
What I gave you is a simple command to view the member of a particular distribution group and each member's department. The script you linked to spits out a report of all DGs and their members. What exactly are you trying to accomplish? What do you want the script to do?
0
pramod1Author Commented:
I just want to validate the members in distribution grouos

Also so that I could create a task schedular to run the ps1 script  every 10 days  to see if all members in that distribution group are intact
0
pramod1Author Commented:
Sorry for any confusion
0
Jamie McKillopIT ManagerCommented:
No problem.

Something like this would work to export each DG to a CSV file

Get-DistributionGroup -ResultSize unlimited | % {
    Get-DistributionGroupMember $_.name | select name,department | export-csv C:\$($_.name).csv
}

Open in new window


Paste that in notepad and save as a .ps1. You can then follow these instructions to run it with task scheduler:

https://community.spiceworks.com/how_to/17736-run-powershell-scripts-from-task-scheduler
0
pramod1Author Commented:
I am looking
0
pramod1Author Commented:
where do I put DL name in this script
0
pramod1Author Commented:
for ex. contoso full time employee is dl name, where should I put it
0
Jamie McKillopIT ManagerCommented:
This particular script will export all of your distribution groups. Are you just looking to run this against one distribution group?
0
pramod1Author Commented:
yes sir, just 3 or 4 not all
0
pramod1Author Commented:
I need to run individually against each DL
0
Jamie McKillopIT ManagerCommented:
For just one, run this:

Get-DistributionGroupMember "Group Name" | select name,department | export-csv "C:\group name.csv"

Open in new window

0
Jamie McKillopIT ManagerCommented:
The original script I provided will run it individually against each DG. After it runs, you will have a separate csv file for each DG.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pramod1Author Commented:
thank you let me validate
0
pramod1Author Commented:
I got the cab file can I sort in excel department wise like all legal in one place then all hr users I have to use filters in excel
0
pramod1Author Commented:
Csv file
0
Jamie McKillopIT ManagerCommented:
Yes, you can manipulate the data however you want in Excel. For example, sort the department column and it will group members by department.
0
pramod1Author Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.