{"id":408,"date":"2017-09-08T15:54:32","date_gmt":"2017-09-08T13:54:32","guid":{"rendered":"https:\/\/msb365.abstergo.ch\/?p=408"},"modified":"2023-06-23T13:12:31","modified_gmt":"2023-06-23T11:12:31","slug":"export-distribution-group-members-one-csv-orand-delete-empty-distribution-groups","status":"publish","type":"post","link":"https:\/\/www.msb365.blog\/?p=408","title":{"rendered":"Export all Distribution Group and All members in one CSV or\/and delete empty Distribution Groups"},"content":{"rendered":"<p>In some situations we have to Export all the Distribution group and all the members of it to a CSV file. There is no command let available to retrieve the distribution group and distribution group members in bulk. Pipe line won\u2019t work in this case.<\/p>\n<p>DisplayName<br \/>\nAlias<br \/>\nRecipientType<br \/>\nRecipient OU<br \/>\nPrimary SMTP address<br \/>\nDistribution Group<br \/>\nDistribution Group Primary SMTP address<br \/>\nDistribution Group Managers<br \/>\nDistribution Group OU<\/p>\n<p><strong><a href=\"https:\/\/twitter.com\/sattzzz\" target=\"_blank\" rel=\"noopener noreferrer\">Satheshwaran Manoharan<\/a><\/strong>\u00a0wrote a script which will make Exchange Administrators life Easy to export distribution group and its members. After checking this Script I thought it would be cool, to be able, that I have a Option to delete all Distribution Groups witch has no Members in.<\/p>\n<p>That&#8217;s why I started first to modify his Script.<\/p>\n<p>First I added for the CSV export two more options (WhenCreated and\u00a0WhenChanged), this helps me, to get more Informations about all Distribution Groups.<\/p>\n<p>After running the Script <span style=\"color: #0000ff;\">.\\DistributionGroupMemberReport.ps1 <span style=\"color: #000000;\">you will get the Menue bellow:<\/span><\/span><\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone wp-image-409 size-full\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2017\/09\/dg-1.png\" alt=\"\" width=\"585\" height=\"330\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2017\/09\/dg-1.png 585w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2017\/09\/dg-1-300x169.png 300w\" sizes=\"(max-width: 585px) 100vw, 585px\" \/><\/p>\n<p>Output of CSV file look like Below<\/p>\n<p>You can add some more entries if required<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-410\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2017\/09\/dg-2.png\" alt=\"\" width=\"640\" height=\"218\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2017\/09\/dg-2.png 640w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2017\/09\/dg-2-600x204.png 600w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2017\/09\/dg-2-300x102.png 300w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/p>\n<blockquote><p>You can download the Script on my Github Page<em><strong> <a href=\"https:\/\/github.com\/MSB365\/DGMemberReport\" target=\"_blank\" rel=\"noopener noreferrer\">here!<\/a><\/strong><\/em><\/p><\/blockquote>\n<p>Please Note! The Initial Script was written by<strong>\u00a0<a href=\"https:\/\/www.linkedin.com\/in\/satheshwaran\/\" target=\"_blank\" rel=\"noopener noreferrer\">Satheshwaran Manoharan<\/a><\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>How to use this Script for Office 365<\/strong><\/p>\n<p>Local desktop . PowerShell \u2013 Run as Administrator<\/p>\n<p>Make Sure your Execution Policy is set to RemoteSigned or Unrestricted<\/p>\n<div>\n<div id=\"highlighter_844745\" class=\"syntaxhighlighter nogutter powershell\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"powershell functions\">Set-ExecutionPolicy<\/code> <code class=\"powershell plain\">RemoteSigned<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>my Case its unrestricted.<\/p>\n<p>To Get Execution Policy Status<\/p>\n<div>\n<div id=\"highlighter_469085\" class=\"syntaxhighlighter nogutter powershell\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"powershell functions\">Get-ExecutionPolicy<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"powershell variable\">$UserCredential<\/code> <code class=\"powershell plain\">= <\/code><code class=\"powershell functions\">Get-Credential<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><code class=\"powershell variable\">$Session<\/code> <code class=\"powershell plain\">= <\/code><code class=\"powershell functions\">New-PSSession<\/code> <code class=\"powershell color1\">-ConfigurationName<\/code> <code class=\"powershell plain\">Microsoft.Exchange<\/code> <code class=\"powershell color1\">-ConnectionUri<\/code> <code class=\"powershell plain\"><a href=\"https:\/\/outlook.office365.com\/powershell-liveid\/\">https:\/\/outlook.office365.com\/powershell-liveid\/<\/a><\/code> <code class=\"powershell color1\">-Credential<\/code> <code class=\"powershell variable\">$UserCredential<\/code> <code class=\"powershell color1\">-Authentication<\/code> <code class=\"powershell plain\">Basic<\/code> <code class=\"powershell color1\">-AllowRedirection<\/code><\/p>\n<div>\n<div id=\"highlighter_694632\" class=\"syntaxhighlighter nogutter powershell\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"powershell functions\">Import-PSSession<\/code> <code class=\"powershell variable\">$Session<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Now Run the Script \u2013 It should work.<\/p>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Photo by\u00a0<a href=\"https:\/\/unsplash.com\/photos\/iU97-bg1rSY?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText\">Dmitry Tsellobenok<\/a>\u00a0on\u00a0<a href=\"https:\/\/unsplash.com\/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText\">Unsplash<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In some situations we have to Export all the Distribution group and all the members of it to a CSV file. There is no command let available to retrieve the distribution group and distribution group members in bulk. Pipe line won\u2019t work in this case. DisplayName Alias RecipientType Recipient OU Primary SMTP address Distribution Group [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3557,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[1923,2,3],"tags":[],"class_list":["post-408","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-microsoft-365","category-exchange","category-powershell"],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/posts\/408","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=408"}],"version-history":[{"count":4,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/posts\/408\/revisions"}],"predecessor-version":[{"id":5205,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/posts\/408\/revisions\/5205"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/media\/3557"}],"wp:attachment":[{"href":"https:\/\/www.msb365.blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=408"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=408"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=408"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}