Manage Distribution Group using PowerShell in Office 365 | view and export information about Distribution Group | Part 4#5 5/5 (3) 10 min read

The current article is that Fourth article on the five-article series, which is dedicated to the subject of managing Distribution Group in Office 365 and Exchange Online based environment using PowerShell.The article includes two main sections:

  1. Management tasks that relate to the need for viewing information about Distribution Group settings, Distribution Group members and so on.
  2. Management tasks that relate to the need of exporting information about Distribution Group.


View information about Distribution Groups

View a list of all existing Distribution Groups

To get a list of all existing Distribution Groups, we use the PowerShell command:

Display all Distribution Groups list + details

PowerShell command Example

Display Distribution Group Members

To get a list of all Distribution Group members, we use the following PowerShell command:

Display Distribution Group Members

PowerShell command syntax

PowerShell command Example

In the following example, we “extend” the information that we get from the basic PowerShell command- Get-DistributionGroupMember.

In this example, we ask from PowerShell to sort the result by the “DisplayName” property, and in addition, display the following properties of the members – DisplayName, Alias, and Department

PowerShell command Example

Count the number of Distribution Group members

In case that we need to count the number of members in a specific Distribution Group, use the following PowerShell command:

PowerShell command Example

Display list of Distribution Groups with specific Email Domain name suffix

In the following example, we want to get information about Distribution Group that their E-mail address includes a specific domain name suffix.

Display list of Distribution Groups with specific Email Domain

PowerShell command syntax

In our specific example, we look for Distribution Group that their E-mail address includes the domain name – o365info.com

PowerShell command Example

Display information about Distribution Group that was updated before or after specific date range.

In some scenario, we need to get a list of Distribution Groups that was created in specific date \Time or Distribution Group that was created in a specific time range.

For example

  • Scenario 1 – We want to add a user to all NEW Distribution Groups, that was created in a specific time range – last two weeks.
  • Scenario 2 – We want to add a user to all Distribution Groups, that was created in a specific time range – all the Distribution Group that was created before the last two weeks.

To be able to “know” when a specific Distribution Group was created, we can query the Distribution Group property – “WhenCreated”.

To be able to find the Distribution Group that “belong” to the specific time range such as the last two weeks or the time before the current two weeks, we need to use the PowerShell logical operators.

In our example, we create two PowerShell queries that will use the following operators – ge and le, and get the following information:

  • Get a list of Distribution Groups, that was created in the last 2 weeks (during the last two weeks). For this purpose, we use the PowerShell operator – ge (Greater than or equal to).
  • Get a list of Distribution Groups, that was created before the last 2 weeks. For this purpose, we use the PowerShell operator – Le (Less than or equal to).

To be able to define the “time range” of two weeks, we will use the PowerShell
cmdlets Get-Date, in the following way: (Get-Date).Adddays(-14).

Get a list of Distribution Groups, that was created in the last 2 weeks

PowerShell command Example

Get a list of Distribution Groups, that was created before the last 2 weeks.

PowerShell command Example

Display all Distribution Groups which their owner (managed by) is user X

In this example, we want to get a list of all Distribution Groups that are managed by Specific user.

get a list of all Distribution Groups that are managed by Adele

PowerShell command Example

Display all Distribution Groups which have a moderator

In this case, we want to get information about Distribution Groups which have a moderator.

For this purpose, we can use a “simple PowerShell command” or a more sophisticated PowerShell command.

In the following example, we ask from PowerShell to get a list of all existing Distribution Groups and present the following properties – display name + the property ModeratedBy.

The information that will be presented will include Distribution Group with a moderator and also without a moderator.

PowerShell command Example

In case that we want to implement more “exact search” that will display only Distribution Group that has a moderator, we can use the following PowerShell command:

PowerShell command Example

Display all Distribution Groups that are synchronized from On-Premise Active Directory

In this example, we want to get a list of all Distribution Groups that are considered as synchronized Distribution Group.

The term synchronized Distribution Group relates to Distribution Groups that was created in On-Premise Active Directory and synchronized with Exchange Online by using Directory synchronization server.

PowerShell command Example

Display Distribution Group information about delivery management

The term “delivery management” describes the setting that relates to “allowed” senders.

The senders Divided into 2 groups:

  1. Internal senders (organization recipients) which describe as authenticated recipients.
  2. External senders (non-organization recipients) which describe as unauthenticated recipients.

In Office 365 the default setting for a new Distribution Group is “Only senders inside my organization.”
In other words, by default, external recipients are not allowed to send an E-mail message to the Exchange Online Distribution Group.

Display Distribution Groups which their delivery management allows external recipients
to send E-mail

In this example, we want to get a list of all Distribution Groups that can accept E-mail from external recipients.

The parameter that defines this option is – RequireSenderAuthenticationEnabled

In case that the value of the parameter – RequireSenderAuthenticationEnabled is – $True, the meaning is that the Distribution Group will accept E-mail from external (non-organization) recipients.

Display Distribution Groups that accept E-mail from external recipients

PowerShell command Example

Display Distribution Groups which their delivery management doesn’t allow external recipients to send E-mail

In this example, we want to get a list of all Distribution Groups that cannot accept E-mail from external recipients.

The parameter that defines this option is – RequireSenderAuthenticationEnabled

In case that the value of the parameter – RequireSenderAuthenticationEnabled is – $True, the meaning is that the Distribution Group will accept E-mail from external (non-organization) recipients.

Display Distribution Groups that doesn’t accept E-mail from external recipients

PowerShell command Example

Get information about Distribution Group membership of a specific user.

In this scenario, we want to get information about the Distribution Group,
which a specific user is a member of.

PowerShell command Example

Export information about Distribution Groups

The section which I describe “export information about Distribution Group” can be considered as a “derivative” of the section in which we use the PowerShell cmdlets “Get-DistributionGroup
or “Get-DistributionGroupMember” for fetching information about the Distribution Group infrastructure (get a list of existing Distribution Group, get information about group membership and so on).

Every information that we can display on the PowerShell console, can also be “exported” to various types of file formats.

File formats and export PowerShell cmdlets

PowerShell supports the option of exporting PowerShell command output to the following file formats: Text, CSV, HTML, and XML.

To be able to export the required information we need to tell PowerShell what is the “file format” that we want to use.

In addition to the PowerShell cmdlet’s that define the specific file format, PowerShell provides a dedicated “export command” for each of the file types and a unique parameter for a specific file type.

For example, when we wish to export PowerShell command output to a CSV (Comma Separated Value) file format, we can add additional parameters such as:

  • –NoTypeInformation – this option prevents from PowerShell to add unnecessary information to the CSV file
  • -Encoding UTF8 – in case that the objects such as users, or mailboxes include non-English characters, we can add this “format parameter” to enable PowerShell export information that includes non-English characters.

The “path” parameter

When we want to export information from a PowerShell command output to a file, we will need to provide PowerShell the exact path and the file name.

The PowerShell command that exports the data will use the “path information,” in creating a new file in the specified path.

Export PowerShell command output to - various file types

It’s important to mention that when we provide a path, such as C:\Temp, the PowerShell command “except” that this path is already created. In other words, by default, the PowerShell command will not “create for us” a specific folder that was specified in the path.

Example of PowerShell syntax for exporting information to various file types

The following section, include a demonstration of exporting PowerShell command output to three types file formats.

To demonstrate the various file format, we use the PowerShell command-
Get-DistributionGroup that as the name implies, get information about existing Distribution Group and by default display the information on the PowerShell console.

In our scenario, we wish to change this default behavior and instead of displaying the information on the PowerShell console, we wish to “redirect” the PowerShell command output to a “File.”

Export information to Text FilePowerShell command Example

Export information to CSV FilePowerShell command Example

Export information to HTML File

PowerShell command Example

The task of exporting information about Distribution Group members to a file could look like a simple task, but this task required some “manipulation” of the PowerShell syntax that we use.
An example of PowerShell command syntax that we can use for exporting information about Distribution Group members to an SCV file could be:

Exporting information about Distribution Group members to a csv file

PowerShell command Example

Manage Distribution Group using PowerShell in Office 365 | Article series index

Now it’s Your Turn!
It is important for us to know your opinion on this article

Summary
Manage Distribution Group using PowerShell in Office 365 | view and export information about Distribution Group | Part 4#5
Article Name
Manage Distribution Group using PowerShell in Office 365 | view and export information about Distribution Group | Part 4#5
Description
Reviewing how to use PowerShell for managing Distribution Group - view and export information about Distribution Group
Author
Publisher Name
o365info.com
Publisher Logo

Related Post

Please rate this

Eyal Doron on EmailEyal Doron on FacebookEyal Doron on GoogleEyal Doron on LinkedinEyal Doron on PinterestEyal Doron on RssEyal Doron on TwitterEyal Doron on WordpressEyal Doron on Youtube
Eyal Doron

Share your knowledge.

It’s a way to achieve immortality.

Dalai Lama


Leave a Reply

Your email address will not be published. Required fields are marked *