office 365 , distribution list

pramod1
pramod1 used Ask the Experts™
on
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.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
timgreen7077Exchange Engineer
Distinguished Expert 2018

Commented:
Connect to O365 and run the following:

(Get-DistributionGroupMember -Identity "name of DL").count
MichelangeloSystem Administrator / Postmaster

Commented:
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

Author

Commented:
What about if I want to find out about members from which department they are from
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Get-DistributionGroupMember "Group Name" | select name,department

Author

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?
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?

Author

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

Author

Commented:
Sorry for any confusion
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

Author

Commented:
I am looking

Author

Commented:
where do I put DL name in this script

Author

Commented:
for ex. contoso full time employee is dl name, where should I put it
This particular script will export all of your distribution groups. Are you just looking to run this against one distribution group?

Author

Commented:
yes sir, just 3 or 4 not all

Author

Commented:
I need to run individually against each DL
For just one, run this:

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

Open in new window

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.

Author

Commented:
thank you let me validate

Author

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

Author

Commented:
Csv file
Yes, you can manipulate the data however you want in Excel. For example, sort the department column and it will group members by department.

Author

Commented:
Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial