Quantcast
Channel: o365info
Viewing all 370 articles
Browse latest View live

Configure WordPress site send E-mail via Exchange Online (Office 365) | Provide user credentials without purchase Office 365 license | Part 5#6

$
0
0
In the current article, we continue to review the scenario in which we want to configure our WordPress site to address Exchange Online server, and implement the best-practice scenario, in which we implement an authenticated mail session (providing Office 365 user credentials).

The main reason in which users often avoid the best practice of providing the required user credential is because that in an Office 365 based environment, the user credentials that we need to provide are the credentials of Office 365 that have Exchange Online license. And most of the time, we try to save the cost of purchasing Office 365 license.

In the current article, we review how to avoid the unnecessary costs of purchasing a decided Office 365 user license that will be used by the WordPress site (the mail account that will be used by WordPress site for addressing Office 365 mail server).

Technically speaking, we can configure the WordPress site to send E-mail using a specific E-mail address such as – support@o365info.com and provide the user credentials of “other Office 365 user”. In case that we will implement this option without implementing the required configuration, the task of “sending E-mail” will fail!

The reason for this “failure” is because, in an Office 365 based environment, Office 365 users A cannot send E-mail on behalf of user B with the required permissions.
A reasonable assumption could be that this issue can be easily solved by adding the ” WordPress site E-mail address” as an alias to the Office 365 user account, which we use his credentials.

Unfortunately, this configuration will not solve the problem because – in Exchange based environment, a recipient cannot send E-mail using his Alias E-mail address. Yes, I know this is sound strange, but you are welcome to try it yourself.

The solution that will answer all of our requirements will be implemented in the following way:

  1. Create a new Exchange Online distribution group

We will create a dedicated Exchange Online distribution group; they will be used for
representing the “WordPress site entity.” In our example, the distribution group will use the
E-mail address – support@o365info.com

  1. Select an Office 365 user who will be used for providing the required user credentials.

The WordPress site will be configured to provide the credentials of existing Office 365 user. In our example, we will use the credentials of Angelina (Angelina@o365info.com).
Angelina is the marketing representative who manages our WordPress site.

  1. Provide the Send As permissions to the Office 365 user

As mentioned, Office 365 cannot just send E-mail using an E-mail address that doesn’t “belong” to him. To be able to configure our WordPress site to use Angelina’s credentials, and at the same time, configure the WordPress site using different E-mail address (the E-mail address that is belonged to the distribution group that was created), we will assign Angelina, the “Send As” permissions on the distribution group that uses the E-mail address support@o365info.com

Using these steps, we can implement the preferred mail communication setting with Exchange Online meaning using authenticated mail session, and at the same time, save the unnecessary, cost of purchasing a decided Office 365 user license.

Implementing authentication by using user with Send As permissions

Note – in the current article series, we use a WordPress mail plugin named – Postman SMTP Mailer/Email Log

1#3 – Configure the SMTP Mailer WordPress plugin | using Office 365 user credentials

In the following section, we review how to configure the required credentials that will be needed for implemented an authentication session with Exchange Online.

Notice that in this phase, we didn’t provide the required “Send As permissions” and the expected result is – that if we try to send E-mail, the task will fail!

  • Login to your WordPress site
  • On the main page (the dashboard), select the Postman SMTP plugin
  • Click on the Settings

Send E-mail using other recipient credentials -01

  • Select the – Show All Settings

Send E-mail using other recipient credentials -02

In the following screenshot, we can see the WordPress site is configured to use the E-mail address – support@o365info.com

The user credentials that were configured are the credentials of Office 365 users named – Angelina.

Send E-mail using other recipient credentials -03

In this step, we will try to send E-mail to destination recipient.

  • In the Postman SMTP setup page, select the menu – Send a Test Email

Send E-mail using other recipient credentials -04

In our example, we send E-mail to Bob

  • Click Next

Send E-mail using other recipient credentials -05

The E-mail delivery failed!

The following error appears:

5.7.60 Client does not have permissions to send as this sender

The meaning of this error is, that we use the credentials of the user who doesn’t have the required permissions to send E-mail on behalf of the “support” (support@o365info.com) E-mail address.

  • In case that we want to get more detailed information, we can select the menu
    option – Session Transcript

Send E-mail using other recipient credentials -06

In the following screenshot, we can see the “recording” of the mail session that occurred between our WordPress site and the destination mail server (Exchange Online in our example).

Send E-mail using other recipient credentials -07

Step 2#3 – Creating a new distribution group + assign Send As permissions

In this section, we will

  • Create a new distribution group and assign the “support E-mail” to the distribution group.
  • Assign Angelina the Send As permissions to the “support group”
  • Login to Exchange Online admin portal
  • On the left menu bar, select the menu recipients
  • On the left menu bar, select the menu groups
  • Click on the plus icon
  • Select the menu – Distribution group

Create a new distribution group that represent the WordPress support -01

Add the required details for the new distribution group. In our example, we will name the new distribution group – Support, and the E-mail address that will be assigned is – support@o365info.com

Create a new distribution group that represent the WordPress support -02

Technically, we don’t have to add members the distribution group. In our example, we will add some members to the distribution group.

  • Click on the plus icon

Create a new distribution group that represent the WordPress support -03

Select the required members

  • Click – add ->
  • Click OK

Create a new distribution group that represent the WordPress support -04

  • Click Save

Create a new distribution group that represent the WordPress support -05

In the following section, we assign the required Send As permissions to Angelina

  • Select the required group, in our example – the support group

Create a new distribution group that represent the WordPress support -06

  • On the left menu bar, select the menu – group delegation
  • Click on the plus icon

Create a new distribution group that represent the WordPress support -07

  • Select the required recipient that will have the Send As permissions. In our example the user is Angelina
  • Click – add ->
  • Click OK

Create a new distribution group that represent the WordPress support -08

  • Click Save

Create a new distribution group that represent the WordPress support -09

Step 3#3 -Send test E-mail uses “other user credentials” with Send As permissions

In the following section, we will test our ability to send E-mail to destination recipient using the E-mail address that represents the WordPress site – support@o365info.com

The credentials that we use are the credentials of Office 365 recipient – Angelina

Send E-mail using other recipient credentials after providing send as permissions -01

An additional configuration that it’s recommended to check is the Message tab

Verify that the E-mail address in the section “From address” is the E-mail address that represents the WordPress site (in our example, support@o365info.com)

Send E-mail using other recipient credentials after providing send as permissions -02

To test mail flow that is sent by the WordPress site, Select the settings of the Post SMTP plugin

In this step, we will try to send E-mail to the destination recipient.

  • In the Postman SMTP setup page, select the menu – Send a Test Email

Send E-mail using other recipient credentials after providing send as permissions -03

In our example, we send E-mail to Bob

  • Click Next

Send E-mail using other recipient credentials after providing send as permissions -04

In the following screenshot, we can see that the E-mail was successfully sent to the destination recipient!

Send E-mail using other recipient credentials after providing send as permissions -05

In case that we look in Bob’s mailbox, we

Send E-mail using other recipient credentials after providing send as permissions -06

Configure your WordPress site to send E-mail via Office 365 or SMTP mail server| Article series index

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

 

The post Configure WordPress site send E-mail via Exchange Online (Office 365) | Provide user credentials without purchase Office 365 license | Part 5#6 appeared first on o365info.com.


Configure your WordPress site to send E-mail via GoDaddy mail server – Shared Hosting plan | Part 6#6

$
0
0
In the current article, we review how to configure a WordPress site that is hosted at GoDaddy, and use a Shared Hosting plan, use the GoDaddy SMTP mail server.

In our scenario, we use the help of Postman SMTP Mailer/Email Log mail plugin.

Before we start, it’s important to me to emphasize that the information about the GoDaddy SMTP infrastructure when using a Shared Hosting plan achieved from “Trial and error” tests, that I have implemented on my WordPress site that is hosted at GoDaddy.

My point is that the information about the GoDaddy SMTP infrastructure when using Shared Hosting can be inaccurate. If you want to be on the safe side, I recommend you to call GoDaddy support.

I try to look for public information about the GoDaddy SMTP infrastructure, and I have found very little information.

As far as I understand, the GoDaddy SMTP infrastructure (when using a Shared Hosting plan) is built in the following way:

When using a Shared Hosting plan, you cannot configure your hosted WordPress site to address an external SMTP mail server. The term “external mail server,” relate to any mail server that is located outside GoDaddy network.

The way I concluded above is by using the Postman SMTP Mailer/Email LogConnectivity Test.

I provide the host name of external mail servers, and execute the port scan process, which tries to verify if my WordPress site can access the “destination mail servers.”

Note – I will demonstrate how to use the Postman SMTP Mailer/Email LogConnectivity Test in the section – xxx

WordPress site using Shared Hosting plan address external mail server

Instead of connecting or addressing “external mail server,” we will need to address a dedicated “GoDaddy SMTP server” that will serve as “our SMTP mail server.”

The host name of this “GoDaddy SMTP server” is – relay-hosting.secureserver.net

Attached a quotation from the GoDaddy support article:

Your server must send mail using our relay servers. This prevents abuse of our network and helps ensure our customers don’t get blacklisted for using the same network as a spammer.

For the most part, you do not need to worry about these settings unless something is not working or you want to use a different mail server daemon on your dedicated machine.

Our servers have an outbound email limit of 1000 per day. If you need to send more than 1000 emails per day, contact customer support.

[Source of information – Find your email relay server]

WordPress site address Godaddy as mail server - Using SMTP session

Regarding the need for proving user credentials, I manage to configure the Postman SMTP Mailer/Email Log mail plugin to send E-mail, without providing any user credentials.

I assume that I manage to do so because, the GoDaddy SMTP server “trust” the internal hosted WordPress site, he is willing to relay the E-mail message to the destination recipients.

WordPress site send E-mail via GoDaddy mail server - Shared Hosting plan

Scenario description – configure WordPress mail plugin to use Exchange Online as a mail server using SMTP

The characters of our scenario are as follows:

  • We need to configure our WordPress website to send an E-mail notification to our organization users. In addition, we will also need to send E-mail to our company customers (external recipients).
  • The public domain name of our organization is – com
  • Our organization purchased – “GoDaddy Shared Hosting plan,” and we want that our WordPress website will use the GoDaddy mail server as “his mail server.”
  • The “identity” that will be used by the WordPress website will be – support@o365info.com
  • We want to configure the Postman SMTP Mailer/Email Log to address GoDaddy mail server
  • The host name of the Exchange Online mail server that host our domain name is-
    relay-hosting.secureserver.net

1#5 – Install the Postman SMTP Mailer WordPress plugin

In this section, we will review how to install the Postman SMTP Mailer/Email Log WordPress plugin.

  • Login to your WordPress site
  • Select the Plugins menu
  • Click – Add New

Using WordPress to send E-mail to Office 365 – install -Postman SMTP Mailer -01

  • In the search box – type postman smtp and hit the Enter key
  • When the search result appears, select the Postman SMTP Mailer/Email Log plugin and click Install Now

Using WordPress to send E-mail to Office 365 – install -Postman SMTP Mailer -02

  • Click on the link – Activate Plugin

Using WordPress to send E-mail to Office 365 – install -Postman SMTP Mailer -03

  • On the left menu bar, select the menu – Plugins
  • Look for the Postman SMTP plugin
  • Click on the Settings menu

Using WordPress to send E-mail to Office 365 – install -Postman SMTP Mailer -04

2#5 – Configure the SMTP Mailer WordPress plugin | Send E-mail via GoDaddy server using SMTP protocol

In the following section, we review how to configure the Postman SMTP plugin, to address GoDaddy SMTP server as a “mail server” using the SMTP protocol.

  • Go to your WordPress website dashboard and look for the Postman SMTP “block”
  • Click on the link – Settings

Using WordPress to address SMTP mail server – GoDaddy using Postman SMTP Mailer -mail server settings -01

  • Select the – Account tab

In the following table, we can see the settings and the values that we will configure in our specific scenario:

Type SMTP Number 1
Transport Settings
Outgoing Mail Server Hostname relay-hosting.secureserver.net Number 2
Outgoing Mail Server Port 25 Number 3
Envelope-From Email Address The “sender” E-mail address Number 4
Security None Number 5
Authentication None Number 6
  • Select the – Save Changes

Using WordPress to address SMTP mail server – GoDaddy using Postman SMTP Mailer -mail server settings -02

  • Select the – Message tab

In this section, we define the “identity” of the WordPress sender who will appear in the E-mail message that will be sent out.

In our example, the E-mail address that we will use as the “sender E-mail address”
is –support@o365info.com

 Using WordPress to address SMTP mail server – GoDaddy using Postman SMTP Mailer -mail server settings -03

  • Select – Save Changes

Using WordPress to address SMTP mail server – GoDaddy using Postman SMTP Mailer -mail server settings -04

3#5 – Send test E-mail recipient | SMTP Mailer WordPress plugin

In the following section, we review the process, in which we verify that the mail server settings were configured correctly.

We want to verify, that we successfully manage to send out E-mail to the recipient from our organization.

The expected results are:

  • The E-mail message will successfully reach the GoDaddy mail server.
  • The GoDaddy mail server will deliver the E-mail message to the destination recipient (Bobm@o365info.com in our example).

Sending test E-mail to organization recipient

  • Select the menu – Send a Test Email

Send test E-mail organization recipient - WordPress send E-mail via Godaddy -SMTP -01

  • In the recipient E-mail address text box, provide the E-mail address of the destination recipient. In our example the recipient is Bobm@o365info.com.
  • Click Next

Send test E-mail organization recipient - WordPress send E-mail via Godaddy -SMTP -02

In the following screenshot, we can see that the E-mail address was successfully sent to the destination recipient.

The meaning is that:

  1. That our WordPress site manage to create an SMTP session with the GoDaddy mail server.
  2. That the GoDaddy mail server “agree” to accept the E-mail.

Send test E-mail organization recipient - WordPress send E-mail via Godaddy -SMTP -03

Now, we want to check what happened to the “other side” meaning – the side of the destination recipient.

In the following screenshot, we can see that the E-mail reaches to Bob’s mailbox. However, it’s important to notice that the E-mail was classified a “spam mail” and for this reason, sent to the junk mail folder!

Send test E-mail organization recipient - WordPress send E-mail via Godaddy -SMTP -04

How does Exchange Online treat “suspicious sender”?

The reason for these “strange phenomena” in which the E-mail address that was sent from the WordPress site reaches the junk mail folder is, because the mail server that host our domain (o365info.com in our example) cannot trust a mail client, that his E-mail address includes our domain name but he didn’t provide any user credentials.

From the mail server point of view, the sender considers “suspicious”!

For this reason, the mail server can decide to reject the E-mail message that sent from the “untrusted sender” or mark the E-mail message as “spam mail.”

In Exchange Online based environment, the Exchange Online mail will not reject or delete the
E-mail that was sent by the “suspicious sender” but instead, “stamp” the E-mail using high SCL value.

  • The “spam grade,” is represented by a value named – SCL (Spam Confidence Level).
  • The SCL score ranges over start with -1 and end with 9.
  • Each E-mail that has a spam score of 2 – 9, consider as spam mail.

Analyzing the information in the E-mail message header

To be able to understand better the reason for this “phenomena,” we will look at the E-mail header content that was sent to Bob.

In our example, we analyze the E-mail header content by using the Microsoft Remote Connectivity Analyzer

Exchange stores the information about the “spam level” of specific E-mail in the mail field-
X-Forefront-Antispam-Report.

In the following screenshot, we can see that Exchange Online stamp the E-mail using SCL=5. The meaning is that there is High chance that the E-mail is sent by “problematic sender.”

Send test E-mail organization recipient - WordPress send E-mail via Godaddy -SMTP -05

When looking at an additional mail field named – X-MS-Exchange-Organization-AuthAs, we can see that the value is – Anonymous

The reason in which the Office 365 mail server “think” that the E-mail is a spam mail is, because the sender uses the domain name that is hosted by Exchange server (o365info.com) but considers as “Anonymous sender” meaning, unauthenticated sender.

Send test E-mail organization recipient - WordPress send E-mail via Godaddy -SMTP -06

Don’t worry!

In the article – Creating Exchange Online bypass spam rule – whitelist specific sender E-mail address | Part 3#6 , I will provide a possible solution for this problem, by creating an Exchange Online bypass spam rule that will treat E-mail that sends by support@o365info.com as a legitimate E-mail message.

4#5 Using the connectivity test options of SMTP Mailer WordPress plugin

In the current section, I would like to review a very useful and powerful feature, that the Postman SMTP Mailer/Email Log mail plugin includes.

The feature name is – Connectivity Test and the purpose of the connectivity test option is to verify that we can access our desired mail server using the specific communication ports such as port 254 and port 587.

In addition, the connectivity test option will try to verify the communication channel with other public mail servers such as Gmail mail servers.

I describe the “connectivity test option” as a very useful and powerful feature because, in many scenarios, the WordPress is hosted by ISP or located in a network that uses Firewall that block mail communication with external hosts (port 25, 587).

When using “other WordPress mail plugins” that doesn’t include this option, the troubleshooting process of “send E-mail Failure” can be quite frustrating.

In a scenario, in which we don’t manage to send E-mail to the destination recipient, it’s very hard to know what is the cause of the problem.

We cannot be sure if the problem relates to the user credentials, the protocol version, the hostname of the mail server or to a problem of firewall that blocks our communication.

Using the Postman SMTP Mailer/Email Log – connectivity test

  • Select the menu option – Connectivity Test

WordPress address SMTP mail server – GoDaddy -Postman SMTP Mailer -implementing Connectivity Test-mail -01

Type the hostname of the mail server that you want to address as “your mail server.”
In our example, we address the Exchange Online mail server using the host name – smtp.office365.com

  • Click – Begin Test

WordPress address SMTP mail server – GoDaddy -Postman SMTP Mailer -implementing Connectivity Test-mail -02

In the following screenshot, we can see the result of the connectivity test. From the result, we can see that the destination mail server is “listing” using port 25 and port 587.

The meaning is that we have an “open communication channel” to the required mail server and that the network Firewall “approve” to use these communication ports.

WordPress address SMTP mail server – GoDaddy -Postman SMTP Mailer -implementing Connectivity Test-mail -03

5#5 – View information about email that mail that sent by using the Postman SMTP Mailer Log files

In the following section, I would like to review the process of accessing information about mail transaction that is stored in the Log file.

One of the features hat I like about the Postman SMTP Mailer/Email Log plugin is – the ability to access the Log file that includes detailed information about each mail transaction.

The ability to look at the log file, enable us to implement a troubleshooting process in case that we experience a scenario of “mail communication failure” for a specific recipient or specific domain.

  • To be able to view information about specific mail transaction, click on the
    link named – In the log

WordPress address SMTP mail server – GoDaddy Postman SMTP Mailer -view SMTP session Log -mail -01

In the following screenshot, we can see an example of the “documentation” of the mail transaction that was implemented.

  • To be able to get details on a specific mail transaction, select the required mail and click on the menu – Session Transcript

WordPress address SMTP mail server – GoDaddy Postman SMTP Mailer -view SMTP session Log -mail -02

In the following screenshot, we can see the “recording” of the session that occurred between our WordPress site (the Postman SMTP Mailer/Email Log plugin) and the destination mail server.

In our specific example, we can see information about the E-mail that we try to send to external recipients. We can see that we manage to connect the Office 365 mail server but the Office 365 mail server “refuse” to accept the “delivery request” to the external recipient (refusing to relay the E-mail)

WordPress address SMTP mail server – GoDaddy Postman SMTP Mailer -view SMTP session Log -mail -03

Configure your WordPress site to send E-mail via Office 365 or SMTP mail server| Article series index

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

 

The post Configure your WordPress site to send E-mail via GoDaddy mail server – Shared Hosting plan | Part 6#6 appeared first on o365info.com.

Configure Exchange Online inbound mail flow to accept SMTP connection only from a specific mail security gateway IP address

$
0
0

In the current article, we will review how to change the default Exchange Online incoming mail policy, which enables any host, to address Exchange Online using SMTP.
A different way of describing such a scenario is – Block SMTP access of external mail servers to Exchange Online.
In our scenario, we want to implement an Exchange Online incoming mail policy in which Exchange Online will “agree” to accept incoming SMTP connection, only from approved “entities.”

Our incoming mail flow scenario

Our scenario, includes the following mail infrastructure:

We use Exchange Hybrid configuration, in which our mail infrastructure is “distributed” between Exchange on-Premises and Exchange Online.

The MX record of our organization domain name (o365info.com), is pointing to the IP address of Mail security gateway

Our organization, need to fulfill a regulatory requirement in which every E-mail that is sent to our organization recipient must reach to the Mail security gateway.

The Mail security gateway implements several security checks.
After the security check is completed, the Mail security gateway will forward the E-mails to the Exchange on-Premises server or to the Exchange Online mail server.

Our organization mail infrastructure is published by using MX record that “point” to on-Premises mail security gateway represented by the IP address 93.157.83.110.

The scenario characters – MX record is pointing to Mail security gateway-

An additional requirement that we need to fulfill is – prevent from the external mail server\s the ability to address the Exchange Online mail server, that represents our domain name “Directly.”

Notice the important observation – although the MX record of our domain name is pointing to the IP address of the Mail security gateway, external hosts who know the IP address of the Exchange Online mail server or know what is the “Office 365 MX record” that represents our hosted domain name, can “bypass” our Mail security gateway by creating an SMTP session with Exchange Online directly.

In other words, we need to implement a mail flow configuration. In which – only the Exchange on-Premises Exchange Hybrid server, and the Mail security gateway are allowed to create an SMTP session with the Exchange Online mail server that represents our domain name.

Block access of external mail servers to Exchange Online except specific IP address-

Another requirement that we need to fulfill is, that the communication channel between the Exchange on-Premises Exchange Hybrid infrastructure and the Exchange Online will not be interrupted by the configuration settings that we will create for restricting the SMTP access to “our Exchange Online mail server”.

We will review this issue in the following section .

How to provide the required solution

The solution for this business requirement, implemented by created a new Exchange Online mail connector, that defines the Exchange Online “incoming mail policy.”

As mentioned, by default Exchange Online is willing to accept SMTP connection from any external host.

In our scenario, we want to “harden” this default behavior so, the Exchange Online mail server that represents our domain name, will accept incoming SMTP connection only from the following “approved” hosts:

  1. The Exchange on-Premises Exchange Hybrid server
  2. The Mail security gateway

To be able to create this “incoming mail flow policy,” we will use two incoming Exchange Online mail connectors.

Exchange Online and the communication channel with Exchange on-Premises Hybrid server

In our example, the organization mail environment is an Exchange Hybrid environment.
When the Exchange Hybrid environment was created, the Exchange Hybrid wizard automatically creates inbound and outbound (send and receive) connectors.

By default, the incoming Exchange Online mail connector is configured to accept SMTP connection from the Exchange on-Premises Exchange Hybrid server, only on the Exchange on-Premises can identify himself (prove his identity).

The Exchange on-Premises “present” his identity by providing a server certificate.

The point is – that Exchange Online had already a “relationship” with the Exchange on-Premises environment. For this reason, we will not need to create a dedicated Exchange Online incoming mail connector for the Exchange Hybrid environment.

Exchange Online and the communication channel with Mail security gateway

To be able to change the default Exchange Online incoming mail policy regarding incoming SMTP connection, we will create a new incoming mail connector (receive connector), that will allow incoming connection only from a specific IP address – The IP address of the Mail security gateway.

Approving the required mail entities which can communicate Exchange Online using SMTP-

Creating new Exchange Online incoming mail connector

In the following section, we will demonstrate how to harden the Exchange Online incoming mail policy, by creating a custom Exchange Online incoming mail connector.

The Exchange Online incoming mail connector will be configured to accept SMTP connections, only from a specific IP address that will be specified in the incoming mail connector settings.

  • Login to Exchange Online admin center
  • On the left menu bar, select mail flow
  • On the left menu bar, select connectors
  • Click on the plus icon

Create a new Exchange Online partner incoming mail connector -01

In the following screenshot, we can see the “structure” of the incoming mail connector.

The first configuration setting defines the two involved parties – the “source” entity (A) and the “destination” entity (B).

Create a new Exchange Online partner incoming mail connector -02

In our scenario,

  • The “source” relates to the mail server that will be “allowed” to connect an Exchange Online server who represent our hosted domain.
  • The “Destination” is the Exchange Online server.

Create a new Exchange Online partner incoming mail connector -03

  • In the section “From,” select the option – Partner organization.

Create a new Exchange Online partner incoming mail connector -04

  • In the section “To,” select the option – Office 365. The term “Office 365” represent the Exchange Online server who host our domain.

Create a new Exchange Online partner incoming mail connector -05

  • In the *Name section, provide a descriptive name for the Exchange Online connector.
  • Notice that the default setting of the new Exchange Online mail connector is set to activate the mail connector, at the end of the process. In case that you consider testing the mail connector setting at a later time, uncheck the option of “Turn it on
  • Click Next

Create a new Exchange Online partner incoming mail connector -06

  • Select the option – Use the sender’s domain
  • Click Next

Create a new Exchange Online partner incoming mail connector -07

  • Click on the plus icon

Create a new Exchange Online partner incoming mail connector -08

  • Add the “*” character. The meaning of this character is “every domain”. In other words, this incoming mail connector settings will be “applied ” for every domain that the “source host” uses. Technically speaking, we can create an incoming Exchange Online mail connector that will be “activate” only in a scenario in which the sender presents himself by using a specific domain name.
  • Click OK

Create a new Exchange Online partner incoming mail connector -09

  • Click Next

Create a new Exchange Online partner incoming mail connector -10

  • Uncheck the option – Reject E-mail messages if they aren’t sent over TLS

By default, Exchange Online relates to “partner organization” connectors, as a connector that defines TLS based communication between two end points (Exchange Online and the “other mail server).

In our scenario, we do not want to configure TLS relationship. For this reason, we will uncheck the “TLS” option.

Create a new Exchange Online partner incoming mail connector -11

  • Select the option – Reject email messages if they aren’t sent from within this IP address range
  • Click on the plus icon

In our example, Exchange Online will identify the “external Mail security gateway” by his public IP address.

Create a new Exchange Online partner incoming mail connector -12

  • Add the IP address of the “external host” that will be allowed to send E-mail to Exchange Online.
  • Click OK

Create a new Exchange Online partner incoming mail connector -13

  • Click Next

Create a new Exchange Online partner incoming mail connector -14

  • Click Save

Create a new Exchange Online partner incoming mail connector -15

In the following screenshot, we can see that a new incoming mail connector was successfully created.

Create a new Exchange Online partner incoming mail connector -16

Testing incoming mail flow | Exchange Online

To be able to verify if we manage to implement the required Exchange Online “incoming mail policy,” we implemented two different tests, in which we try to verify that the Exchange Online mail server that represents our domain name (o365info.com in our scenario) is willing to accept an SMTP connection requests only from an “approved entity.”

We will use SMTP mail client, that will address the MX record of the Exchange Online mail server that represents the domain name – o365info.com

In our example, the Exchange Online that host my domain name is represented by the host name – o365info-com.mail.protection.outlook.com

The mail client that I use for implementing the required incoming SMTP communication tests is, a nice and useful Mail client utility named – Basic SMTP Telnet Client

Test 1#2 – Try to create an SMTP session using “Approved” host.
In this test, we will address the MX record of the Exchange Online mail server that represents our domain name, from a host, that his IP address was configured in the Exchange Online incoming mail connector.

The expected result is, that the Exchange Online will accept the request for SMTP connection.

Test 2#2 – Try to create an SMTP session using “non-approved” host.
In this test, we will verify of “unapproved” host, can create an SMTP session with the Exchange Online server who host our domain.

The expected result is, that the Exchange Online will refuse to accept the request for SMTP session, from a host whom his IP address was not added to the incoming Exchange Online mail connector.

Testing the incoming Exchange Online mail connector settings

Testing SMTP session using “Approved” host.

In the following screenshot, we can see the configuration of the SMTP mail client that was installed on a “non-approved” host.

  • Destination mail server – in the section named – Receive Connector IP, we add the host name or the IP address of the destination mail server (number 1).
  • The TCP port that we use is the standard SMTP port – port 25 (number 1).
  • The sender E-mail address that we use is – Bobm@o365info.com (number 3).
  • The destination recipient E-mail address that we use is also – Bobm@o365info.com (number 4).

Note – in case that you need to get more information about – how to locate the information about the Exchange Online MX record for a specific domain, you can read the article – What is the hostname of my Office 365 MX records?

Testing SMTP connection to Exchange Online mail server – approved IP address -01

We select the Talent tab, which enables us to start the SMTP session with the destination mail server and in addition, to view the communication “chat” between our mail client and the mail server.

In our example, the communication channel between the mail client and the Exchange Online mail server was successfully completed.

The Exchange Online responds with the following message:

transmitting body 250 2.6.0 <5f229770-5b32-4cc0-a54d-4a3456d89918@AM1FFO11FD041.protection.gbl> [InternalId=115027814122736, Hostname=DB3PR05MB091.eurprd05.prod.outlook.com] 7155 bytes in 0.160, 43.503 KB/sec Queued mail for delivery

The meaning is that the Exchange Online mail server is willing to accept the E-mail and inform the mail client that the E-mail is located in the queue, waiting for a delivery

Testing SMTP connection to Exchange Online mail server – approved IP address -02

Testing SMTP session using “Non-Approved” host.

In the following screenshot, we can see the configuration of the SMTP mail client that was installed on a “non-approved” host.

The main difference versus the former scenario is – that this time; the SMTP client is installed in a host who has an IP address that doesn’t consider as “approved“ IP address, by Exchange Online mail server.

Testing SMTP connection to Exchange Online – NON approved IP address -01

We select the Talent tab, which enables us to start the SMTP session with the destination mail server.

The SMTP communication results with the Exchange Online mail server is – failure.

The Exchange Online mail server responds with the following message:

rcpt to: Bobm@o365info.com

550 5.7.51 TenantInboundAttribution; There is a partner connector configured that matched the message’s recipient domain. The connector had either the RestrictDomainsToIPAddresses or RestrictDomainsToCertificate set

This is a “‘good result” or the expected result. In our scenario, we don’t want that the Exchange Online mail server that represents our domain, will agree to accept an SMTP communication requests from non-approved hosts.

Testing SMTP connection to Exchange Online – NON approved IP address -02

Verifying the communication channel between Exchange on-Premises Hybrid server and Exchange Online

In this section, I would like to briefly review the configuration of the communication channel between – Exchange Online and the Exchange on-Premises Hybrid server.

As mentioned, in our scenario, there are two “entities” that are “allowed” to communicate with the Exchange Online mail server:

  • The Mail security gateway
  • The Exchange on-Premises Hybrid server

In the former sections, we review the settings of the Exchange Online incoming mail connector that defines the “relationship” with the Mail security gateway.

The question that we can ask now is – how can we know, that the restriction that we define on the Exchange Online incoming mail connector, will not interfere with the communication channel with the Exchange on-Premises Hybrid server?

The incoming mail connector the was created, define who are the “allowed” hosts who can communicate with Exchange Online mail server, include only the IP address of the Mail security gateway! (And does not relate to the Exchange on-Premises Hybrid server).

The answer is – that when the Exchange Hybrid environment was created, the Exchange Hybrid wizard automatically created Exchange Online incoming mail connector, that defines the relationship with the Exchange on-Premises Hybrid server.

The Exchange Online mail server identifies or recognize the Exchange on-Premises Hybrid server, by looking for a specific text string that needs to be included on the certificate that the Exchange on-Premises Hybrid server provide.

Exchange Online approve SMTP session -Exchange on-Premises Exchange Hybrid server server certificate

The outcome is that in our specific scenario, Exchange Online will include two incoming mail connectors:

  1. The incoming mail connector that defines the relationship with the Mail security gateway (recognize the sender by IP address).
  2. The incoming mail connector that defines the relationship with them Exchange on-Premises Hybrid server (recognize the sender by a public certificate).

In other words, the Exchange Online mail server can have “multiple relationships” with multiple “source senders,” that will not Interfere with each other.

Checking the incoming mail connector for the Exchange Hybrid environment

To be able to view the incoming mail connector, we will implement the following steps:

In the following screenshot, we can see an example of the Exchange Online incoming mail connector that defines the relationship with the Exchange on-Premises Hybrid server:

Verifing the information about incoming mail flow Exchange on-Premises Hybrid environment -01

The mail connector is an “incoming mail connector,” that will be “active” each time that the Exchange on-Premises Hybrid server will address the Exchange Online mail server.

Verifing the information about incoming mail flow Exchange on-Premises Hybrid environment -02

In the following screenshot, we can see that the Exchange Online incoming mail connector includes the following setting:

By verifying that the subject name of the certificate that the sending server uses to authenticate with Office 365 matches this domain name (recommended) This option requires all email messages from your email server to be sent over Transport Layer Security (TLS), a secure channel. Your email server secures this channel by authenticating with Office 365 using a digital certificate. Office 365 then verifies that the subject name in the digital certificate matches the domain name specified here. The domain name can contain wildcard characters.

In simple words, Exchange Online will verify SMTP communication coming from the Exchange on-Premises Hybrid server by checking the following parts:

  • That the Exchange on-Premises Hybrid server can provide a certificate.
  • That the certificate is valid.
  • That the certificate includes a specific text string.

Verifing the information about incoming mail flow Exchange on-Premises Hybrid environment -03


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

 

The post Configure Exchange Online inbound mail flow to accept SMTP connection only from a specific mail security gateway IP address appeared first on o365info.com.

Manage Distribution Group using PowerShell in Office 365 | Creating and managing Distribution Groups | Part 2#5 5/5 (2)

$
0
0

The current article is that second 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. Creating New Distribution Group.
  2. Configure the setting of existing Distribution Group.

Updating Distribution Group and the error – You don’t have sufficient permissions

Each Distribution Group has at least one “owner.”

Technically speaking, only the Distribution Group owner is “allowed” to perform management tasks such as updated to the Distribution Group.

In case that Exchange Online Administrator tries to update properties of Distribution Group, which he is not the owner of this Distribution Group, in some scenarios, the following error message appears:

You don’t have sufficient permissions. This operation can only be performed by a manager of the group.

Notice that although the user performing an update of the Distribution Group properties has Global Administrator credentials, the fact that he is not the Distribution Group owner could “stop” him from complete the required management task.

The good news is that the PowerShell cmdlets that we use for managing Distribution Group include a parameter named – BypassSecurityGroupManagerCheck.
In case that you try to perform a management task, and the “permission error” appears, you can add the BypassSecurityGroupManagerCheck parameter to the “original PowerShell command.”

For example

PowerShell command syntax

Set-DistributionGroup -Identity "<Distribution Group Name>" –ManagedBy <Identity> -BypassSecurityGroupManagerCheck

Creating New Distribution Group

When we use PowerShell for creating a NEW Distribution Group without any parameters besides of the Distribution Group name, the Distribution Group will be created with the following default options:

  • E-mail address – the default E-mail address that will be created for the NEW Distribution Group will include the tenant onmicrosft.com domain name.
  • Delivery management – the default option that will be set is – “Only senders inside my organization.” The meaning is that the external recipient will not be allowed to send E-mail to the Distribution Group.
  • Ownership = The Distribution Group ownership will be assigned automatically to the user account that creates the Distribution Group.

One option is to use PowerShell for creating a NEW Distribution Group, and in the second, phase set all the required settings.

The other option is to use a PowerShell command with additional parameters, that will create the NEW Distribution Group + set additional setting’s options.

Create NEW Distribution Group (use default settings).

PowerShell command syntax

New-DistributionGroup -Name "<Distribution Group Name>"

PowerShell command Example

New-DistributionGroup -Name “Sales USA”

Create NEW Distribution Group + set additional Distribution Group settings.

In case that we want to avoid from the default settings of a NEW Distribution Group when we create the Distribution Group by using PowerShell, we can “extend” that information that we provide to the PowerShell command, so we will be able to better control results.

In the following table, we can see an example to a parameter that we can use when running a PowerShell command for creating a NEW Distribution Group:

PowerShell Parameter Description
Alias In case that we don’t provide an Alias name for the NEW Distribution Group, the Alias name will be automatically generated using the Distribution Group name but without spaces.
Name This is a mandatory value. The Name parameter specifies the unique name of the group. The maximum length is 64 characters. If the value contains spaces, enclose the value in quotation marks (“).
Display name In case that we don’t provide the Display name, the display name default value is the “text” that appears in the parameter “name.”
PrimarySmtpAddress When creating, a new Distribution Group the only option that relates to E-mail address identity to set the Distribution Group primary E-mail address. (When using the PowerShell cmdlets Set-DistributionGroup.
We can also use the parameter EmailAddresses for creating Alias E-mail address.
ManagedBy The ManagedBy parameter, specifies an owner for the group. A group must have at least one owner. If you don’t use this parameter to specify the owner when you create the group, the user account that created the group is the owner.

Create NEW Distribution Group + set additional Distribution Group settings.

PowerShell command syntax

New-DistributionGroup -Name <Distribution Group name> -DisplayName <DL display name> 
-Alias <Alias>-PrimarySmtpAddress <Email Address> -ManagedBy <identity>

PowerShell command Example

New-DistributionGroup -Name “Sales USA” -DisplayName “Sales USA mail list” -Alias “SalesUSA”
-PrimarySmtpAddress SalesUSA@o365info.com -ManagedBy Brad

Create NEW Security Distribution Group

In case that we want to create a Distribution Group but in addition, define the NEW Distribution Group as a “security group” (a group which can be assigned with permissions), we can use the PowerShell parameter “Type Security.”

In this case, the NEW group will have all the “properties” of Distribution Group and in addition, will also we considered as a “Security Group.”

Create NEW Security Distribution Group

PowerShell command syntax

New-DistributionGroup -Name <Distribution Group Name> -Type Security

PowerShell command Example

New-DistributionGroup -Name “Sales Italy” -Type Security

Creating Distribution Groups by importing information from a CSV File

The main use of such a requirement is a scenario in which the organization has an existing mail information or other organization application that includes already information about existing Distribution Groups.

In this case, we would like to avoid the need of creating manually a large amount of Distribution Group using the Exchange Online admin center.

Instead, we wish to “bulk creates” the Distribution Groups by importing the information from a CSV file.

Besides of importing the information about the Distribution Group name, we can add to the CSV file additional parameters such as the “type” of the Distribution Group (standard Distribution Group or a security Distribution Group).

Creating Distribution Groups by importing information from a CSV File

PowerShell command syntax

Import-CSV <Path> | ForEach {New-DistributionGroup -Name $_.name -Type $_.Type}

PowerShell command Example

Import-CSV C:\Temp\DL-Group.csv | ForEach {New-DistributionGroup -Name $_.name -Type $_.Type}

Creating Distribution Groups by importing information from a CSV File

Note – You can download the CSV files that we use in the article for a demonstration purpose.


2. Manage existing Distribution Group settings

Enable or disable Distribution Group to get E-mail from external senders

By default, the Exchange Online Distribution Group is configured not to accept email messages from recipients, which are not organization recipients (external senders).

In case that we want to enable an external recipient to send E-mail to the Exchange Online Distribution Group, we can use the PowerShell parameter – RequireSenderAuthenticationEnabled.

By default, the Distribution Group value RequireSenderAuthenticationEnabled is equal to “$True”.

The meaning is that non-authenticated recipient (anonymous recipient or non-organization recipients),
will get an NDR (Non-Delivery Report) message when they try to send an E-mail to the Office 365 Distribution Group.

Enable or disable Distribution Group to get E-mail from external senders

To enable the external recipient to send E-mail to Exchange Online Distribution Group, we set the value of the parameter “RequireSenderAuthenticationEnabled” to $False.

PowerShell command syntax

Set-DistributionGroup "<Distribution Group Name>" -RequireSenderAuthenticationEnabled $False

PowerShell command Example

Set-DistributionGroup  “Sales USA” -RequireSenderAuthenticationEnabled $False

Enable an external recipient to send E-mail to all Distribution Groups (bulk mode).

In case that we want to change the default setting of the delivery management to every Distribution Group at once (bulk mode) we can use the following PowerShell command:

Enable an external recipient to send E-mail to all Distribution Groups (bulk mode).

PowerShell command Example

Get-DistributionGroup | Set-DistributionGroup  -RequireSenderAuthenticationEnabled $False

Adding or replacing Distribution Group owner

In the following section, we review a couple of scenarios that relate to the subject of managing the Distribution Group owner.

The ManagedBy parameter specifies an owner for the group. A group must have at least one owner. If you don’t use this parameter to specify the owner when you create the group, the user account that created the group is the owner. The group owner can:

  • Modify the properties of the group
  • Add or remove group members
  • Delete the group
  • Approve a member depart or join requests (if available)
  • Approve messages sent to the group if moderation is enabled, but no moderators are specified.

By default, the person who creates a group is the owner. All groups must have at least one owner, and Distribution Group can have multiple owners.

Note – in some scenarios in case that the Distribution Group has an existing owner, we will get an error message when we try to update the existing owner information that informs us that we cannot make the required change because we are not the owner of the Distribution Group.

To be able to “bypass” this limitation, we can add to the PowerShell command the parameter – BypassSecurityGroupManagerCheck.

Scenario 1 – Replace existing Distribution Group owner

In this scenario, the Distribution Group already have an owner, and we wish to replace the current Distribution Group owner by assigning a NEW Distribution Group owner\s.

The PowerShell command that we use is:

Replace existing Distribution Group owner

PowerShell command syntax

Set-DistributionGroup -Identity "<Distribution Group Name>" –ManagedBy <Identity>

PowerShell command Example

Set-DistributionGroup -Identity "Sales USA" -ManagedBy Brad -BypassSecurityGroupManagerCheck

Scenario 2 – Adding additional owner\s to Distribution Group

In the current scenario, we would like to “keep” existing Distribution Group owner and add additional Distribution Group owners (versus the former scenario in which we “remove” existing Distribution Group owner and replace this owner by providing the name of a NEW Distribution Group owner).

To be able to fulfill this requirement, we will not use the “standard” PowerShell syntax and instead, we use the following PowerShell syntax to add or remove one or more values without affecting any existing entries: @{Add=””,””…; Remove=””,””…}.

Adding additional owner\s to Distribution Group

PowerShell command syntax

Set-DistributionGroup “<Distribution Group name>” -ManagedBy  
@{Add='<Identity 1>','<Identity 2>'}

PowerShell command Example

Set-DistributionGroup “Sales USA” -ManagedBy  @{Add='bob','brad'}

Scenario 3 – Adding additional owner\s to Distribution Group + removing existing Distribution Group owners.

In the current scenario, we have Distribution Group that has a couple of owners.

We wish to implement the following requirements:

  • Add NEW Distribution Group owners.
  • Remove some of the existing Distribution Group owners.

To be able to fulfil this requirement, we use the following PowerShell command syntax:

Adding additional owner\s to Distribution Group + removing existing Distribution Group owners

PowerShell command syntax

Set-DistributionGroup “<Distribution Group name>” -ManagedBy  @{Add='<Identity 1>','<Identity 2>'; Remove='<Identity 1>' }

PowerShell command Example

Set-DistributionGroup “Sales USA” -ManagedBy  @{Add='bob','bradp' ; Remove='Angelina' }

Scenario 4 – Replace existing Distribution Group owner and import “NEW Distribution Group owner” from a CSV file.

In this scenario, the information about the Distribution Group + the users who will be configured as the Distribution Group owner is stored in a CSV file.

In the following screenshot, we can see the content of the CSV file that we use.
The CSV file includes two columns:

  1. GroupName – this is the column header that stores the information about the Distribution Groups.
  2. ManagedBy – this is the column header that stores the information about the user name that we wish to define as the Distribution Group owner.

Replace existing Distribution Group owner and import NEW Distribution Group owner from a CSV file

In our example, the CSV file name is Distribution-Groups-information.csv

Replace existing Distribution Group owner and import “NEW Distribution Group owner” from a CSV file.

PowerShell command Example

$GroupList = Import-CSV C:\temp\Distribution-Groups-information.csv
ForEach ($group in $GroupList)
{
ForEach ($user in $GroupList)
{
}
Set-DistributionGroup -BypassSecurityGroupManagerCheck -Identity $group.GroupName -managedby $user.ManagedBy
}

Note – You can download the CSV files that we use in the article for a demonstration purpose.

Scenario 5 – Assign Distribution Group owner (replacing the existing Distribution Group owner) for all existing Distribution Groups (Bulk mode).

In the current scenario, we wish to define a specific user as the owner of all existing Distribution Groups. Notice that in this case, we want to remove (replace) the existing Distribution Group owner and assign a NEW owner of the Distribution Group.

Note – in case that you need to add the username as the additional Distribution Group owner instead of replacing existing Distribution Group owner, use the PowerShell syntax that appears in the former section.

The first part of the PowerShell command gets we get a list of every existing Distribution Group.

The second part of the PowerShell command will add the specific user as an owner to the list of the Distribution Group that we got from the first part.

In case that we want to add a specific owner to all existing Distribution Groups, we can use the following PowerShell syntax:

Assign Distribution Group owner (replacing the existing Distribution Group owner) for all existing Distribution Groups (Bulk mode).

PowerShell command syntax

Get-DistributionGroup |Set-DistributionGroup -ManagedBy <Identity> 
–BypassSecurityGroupManagerCheck

PowerShell command Example

Get-DistributionGroup | Set-DistributionGroup -ManagedBy Brad –BypassSecurityGroupManagerCheck

Scenario 6 – Assigning Distribution Group owner (replacing the existing Distribution Group owner) for all Distribution Groups that was created in the last two weeks (Bulk mode).

In the following example, we want to add the user Brad as a Distribution Group owner for all the Distribution Group that was created in the last 2 weeks.

  • Part 1#2 – in the first part of the PowerShell command, we define the PowerShell variable
    named – $AllNewDistributionGroups, that will store the output of a PowerShell query that “fetch” all the Distribution Group that their “creation time value” is a date that included in the “two weeks range” that we define.
  • Part 2#2 – In the second part of the PowerShell command, we use the “ForEach” PowerShell statement, for executing a “loop process” on the results (add Bob to each of the Distribution Group that appear on the list as an Owner).

The PowerShell “time unit” that we use

PowerShell doesn’t include a parameter that defines “week” as a “Time unit.” To be able to define two-week time range, we define a time range of 14 days.

Assigning Distribution Group owner (replacing the existing Distribution Group owner) for all Distribution Groups that was created in the last two weeks

PowerShell command Example

$AllNewDistributionGroups  = Get-DistributionGroup | Where {$_.WhenCreated –ge ((Get-Date).Adddays(-14))}
ForEach ($Group in $AllNewDistributionGroups)
{
Set-DistributionGroup -Identity $Group.name –ManagedBy Bob
}

Manage Distribution Group E-mail address

Each Distribution Group must have a primary email address and may have an additional E-mail address that described as “Alias E-mail address” or “Proxy E-mail addresses.”

The management of Distribution Group E-mail address, can be implemented by using one of the following methods:

  1. Add additional E-mail address to existing Distribution Group E-mail address.
  2. Add additional E-mail address that will “replace” (delete) existing Distribution Group
    E-mail address.
  3. Removing an existing E-mail address

Set Distribution Group Primary E-mail address

To replace existing Distribution Group primary E-mail address (defined by the PowerShell
parameter –PrimarySmtpAddress), we can use one of the following PowerShell command options:

Set Distribution Group Primary E-mail address

PowerShell command syntax

Set-DistributionGroup "<Distribution Group name>" -PrimarySmtpAddress <primary E-mail address>

PowerShell command Example

Set-DistributionGroup "Sales UK" -PrimarySmtpAddress SalesUK@o365info.com

Another variation

PowerShell command syntax

Set-DistributionGroup "<Distribution Group name>" SMTP:<primary E-mail address>

PowerShell command Example

Set-DistributionGroup "Sales UK" -emailaddresses SMTP:SalesUK@o365info.com

Set Distribution Group Primary E-mail address by importing information from a CSV file

In this scenario, the information about the Distribution Groups + the E-mail addresses that should be assigned as primary E-mail address is stored in a CSV file.

In the following screenshot, we can see the content of the CSV file that we use.
The CSV file includes two columns:

  1. GroupName – this is the column header that stores the information about the Distribution Groups.
  2. email – this is the column header that stores the information about the user name that we wish to define as the Distribution Group owner.

Set Distribution Group Primary E-mail address by importing information from CSV file

In our example, the CSV file name is Distribution-Groups-information.csv

Set Distribution Group Primary E-mail address by importing information from a CSV file

PowerShell command Example

$GroupList = Import-CSV C:\temp\Distribution-Groups-information.csv
ForEach ($group in $GroupList)
{
ForEach ($email in $GroupList)
{
}
Set-DistributionGroup -BypassSecurityGroupManagerCheck -Identity $group.GroupName -PrimarySmtpAddress $email.email
}

Note – You can download the CSV files that we use in the article for a demonstration purpose.

Manage Distribution Group Alias E-mail address

The term “Alias E-mail addresses” describe an additional E-mail address beside of the Primary E-mail address.

The process of adding an Alias E-mail address to existing Distribution Group can be implemented in one of the following ways:

  1. Replacing existing Alias E-mail addresses
  2. Adding an additional Alias E-mail address to existing Distribution Group E-mail addresses.

To manage Distribution Group E-mail addresses, we use the PowerShell cmdlets-
Set-DistributionGroup + the PowerShell parameter emailaddresses.

Example 1 – Add additional E-mail address to existing Distribution Group E-mail address.

In this scenario, we wish to keep existing Distribution Group Alias E-mail addresses and in addition, add additional Alias E-mail addresses.

The PowerShell parameter that we use for adding the additional E-mail addresses is – “@{Add”.

In the following example, the Distribution Group “Sales UK” includes existing Alias E-mail addresses, and we add additional Alias E-mail addresses:

Add additional E-mail address to existing Distribution Group E-mail address

PowerShell command Example

Set-DistributionGroup “Sales UK” -emailaddresses @{Add='
SalesUK02@o365info.com','SalesUK02@o365info.com','SalesUK02@o365info.com'}

Example 2- Replace (remove) existing Distribution Group Alias E-mail addresses and add a NEW E-mail address to Distribution Group.

In this scenario, we wish to remove existing E-mail addresses and “replace” the existing E-mail address with a “NEW set” of E-mail addresses.

The “catch” with the following suggested PowerShell command was that the result will be

“Replacement“ of the primary E-mail address + Replacement of existing Distribution Group
Alias E-mail addresses.

The first E-mail address that we provide will replace the existing Distribution Group Primary E-mail address, the rest of the E-mail addresses will replace existing Distribution Group Alias E-mail addresses.

Replace (remove) existing Distribution Group Alias E-mail

PowerShell command Example

Set-DistributionGroup “Sales UK” -emailaddresses 'SalesUK02@o365info.com', 'SalesUK03@o365info.com'

Because of the problematic behavior of the PowerShell command, I suggest that you try to avoid the use of the specified PowerShell syntax.

Example 3- Replace Distribution Group existing E-mail address – Primary + Alias E-mail address

In the following example, we replace existing Distribution Group E-mail addresses by replacing the current Distribution Group Primary E-mail address + replacing the existing Alias E-mail address.

To “declare” a specific E-mail address as a “Primary E-mail address” we use the prefix SMTP with a capital letter. All the rest of the E-mail addresses will be created as Alias E-mail addresses.

Replace Distribution Group existing E-mail address – Primary + Alias E-mail address

PowerShell command syntax

Set-DistributionGroup "<Distribution Group Name>" -EmailAddresses SMTP:<Primary Email>,<Alias Email>

PowerShell command Example

Set-DistributionGroup "Sales UK" –EmailAddresses SMTP:DL-USA@o365info.com,dev@o365info.com

Example 4- Remove existing Distribution Group Alias E-mail addresses

In the following example, we wish to remove Distribution Group Alias E-mail address \ addresses.

To implement the required removal, we use the PowerShell parameter “@{Remove”.

Remove existing Distribution Group Alias E-mail addresses

PowerShell command syntax

Set-DistributionGroup “<Distribution Group name>” -EmailAddresses @{Remove='<Identity 1>', '<Identity 2>' }

PowerShell command Example

Set-DistributionGroup "Sales UK" -EmailAddresses @{Remove=' Sales01@o365info.com', ' Sales02@o365info.com' }

Hide Distribution Group from GAL (Global address list).

By default, every Distribution Group appears automatically in the GAL.

In some scenarios, we wish to hide existing Distribution Group by removing the information about the existing Distribution Group from the GAL (Global address list).

To hide existing Exchange Online recipient from the GAL, we use the PowerShell parameter – HiddenFromAddressListsEnabled and set the value to – $True.

Hide Distribution Group from GAL (Global address list)

PowerShell command syntax

Set-DistributionGroup "<Distribution Group Name>" -HiddenFromAddressListsEnabled $True

PowerShell command Example

Set-DistributionGroup "Sales UK" -HiddenFromAddressListsEnabled $True

Set an existing Distribution Group to accept E-mail only from a specific sender

By default, every organization recipient can send E-mail to Distribution Group.

In case that we want to restrict the ability of an organization recipient to send E-mail to a specific Distribution Group, and define that only specific organization recipient will be allowed to send E-mail to the Distribution Group, we can use the PowerShell parameter –AcceptMessagesOnlyFrom to define the “allowed recipient list.”

Set an existing Distribution Group to accept E-mail only from a specific sender

PowerShell command syntax

Set-DistributionGroup "<Distribution Group Name>" –AcceptMessagesOnlyFrom <Allowed E-mail address 1>, < Allowed E-mail address 2>

PowerShell command Example

Set-DistributionGroup "Sales UK" –AcceptMessagesOnlyFrom Bradp@o365info.com,Angelina@o365info.com

Define a Distribution Group Moderator

Distribution Group moderator

By default, when we send an E-mail to a Distribution Group, the E-mail is sent automatically to each of the Distribution Group members.

In some scenario, we need to implement a different mail flow, in which E-mail message that is sent to a Distribution Group, will be “accepted” by a specific recipient\s.

The recipient\s which will get the mail need to decide if they approve or decline the
specific E-mail message.

The “person” that we can allocate for this role defined as “Distribution Group Moderator.”

The term “Distribution Group Moderator,” define an entity that needs to approve messages sent to the recipient (Distribution Group members) before the messages are delivered. A moderator must be a mailbox, mail user, or mail contact in your organization.

To PowerShell parameter that we use for defining a “Distribution Group Moderator” is – ModeratedBy.

Define a Distribution Group Moderator

PowerShell command syntax

Set-DistributionGroup "<Distribution Group Name>" –ModeratedBy <E-mail address>, <E-mail address>

PowerShell command Example

Set-DistributionGroup "Sales UK" –ModeratedBy Bradp@o365info.com,Angelina@o365info.com

Send out of office reply for a Distribution Group

Let’s start with a declaration – The title is a little misleading.

Technically speaking, a Distribution Group object is not an “Exchange mailbox object,” and for this reason, we cannot configure OOO (Out Of Office reply) for existing Distribution Group.

The little trick that we can use, that will partially answer the requirement of defining OOO reply to Distribution Group, is implemented by activating a special Distribution Group parameter named – SendOofMessageToOriginatorEnabled and set the value to $True.

(By default, the value – SendOofMessageToOriginatorEnabled is set to “$False”).

When we “activate” this option, in case that one of the Distribution Group members configures an OOF reply, when a “sender” sends an E-mail message to the Distribution Group, the Distribution Group will “reply” with the OOF messages of the Distribution Group member.

The SendOofMessageToOriginatorEnabled parameter specifies how to handle out of office (OOF) messages for members of the group.

Valid values are:

  • $True When messages are sent to the group, OOF messages for any of the group members are sent to the message sender. This is the default value.
  • $False When messages are sent to the group, OOF messages for any of the group members aren’t sent to the message sender.

Send out of office reply for a Distribution Group

PowerShell command syntax

Set-DistributionGroup "<Distribution Group Name>" –SendOofMessageToOriginatorEnabled $True 

PowerShell command Example

Set-DistributionGroup "Sales UK" –SendOofMessageToOriginatorEnabled $True 

Assign “Send As” Permissions to Distribution Group

Assigning Send as permissions to a recipient “on” a Distribution Group, enable the recipient to send E-mail by “hiding” his real identity, and using the identity of the Distribution Group (using the E-mail address of the Distribution Group).

Assign Send As Permissions to Distribution Group

To be able to grant this permission, we can use the following PowerShell command:

Assign “Send As” Permissions to Distribution Group

PowerShell command syntax

Add-RecipientPermission "<Distribution Group Name>" -Trustee <Identity> -AccessRights SendAs -Confirm:$False

PowerShell command Example

Add-RecipientPermission "Sales UK" -Trustee Brad -AccessRights SendAs -Confirm:$False

Note – we add the PowerShell parameter “Confirm:$False” to avoid the need of conforming the “adding” of the Send As permissions.

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

Please rate this

The post Manage Distribution Group using PowerShell in Office 365 | Creating and managing Distribution Groups | Part 2#5 5/5 (2) appeared first on o365info.com.

Manage Distribution Group using PowerShell in Office 365 | Adding members to existing Distribution Group | Part 3#5 5/5 (1)

$
0
0

The current article is that third 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 is dedicated to the subject of adding members to existing Distribution Group by using PowerShell.

Adding members to Distribution Group – prefix

In the next sections, we review two main scenarios, in which we need to add a “NEW member” to existing Distribution Group.

  • Scenario 1#2 – in this scenario, we want to add a “bulk” of users to a specific Distribution Group (many to one relationship).
  • Scenario 2#2 – in this scenario we want to add a specific user to “bulk” of Distribution Groups (one to many relationship).

The management task of adding new members to Distribution Group, is implemented by using the PowerShell cmdlet – Add-DistributionGroupMember.

Working with Distribution Group lists and Distribution Group member lists.

In the next section, we work with a concept which can be described as – “Group,” “list” or if we want to use the more technical term – “Array.”

This term defines a logical container, that “store objects (members)

In the specific scenario, we will use an “Array,” that contain user objects or Distribution Group objects.

The concept of Array

In our example, we create an “array” by using one of the following methods:

  • Option 1 – “array” that is created from the output from of a varies PowerShell commands.
    For example, the list of existing Distribution Group that we get from the
    PowerShell command – Get-DistributionGroup
  • Option 2 – using a file as a “source” for the “array”.
    In this case, we use a file (most of the time CSV file) that includes a list of Distribution Groups, a list of users and so on.
  • Option 3 – creating “array” by manually providing the “list” of the required Distribution Group or a list of Users. In this case, we manually provide the name of each Distribution Group or each user, separated by a comma.

The posable options for creating an array in PowerShell

Scenario 1 – Add a user (recipient) to a Distribution Group

This is a simple scenario, in which we wish to add a specific user to a Distribution Group.

In this example, we “write down” the name of the Distribution Group and the name of the “member” which will be added to the Distribution Group.

Add a user (recipient) to a Distribution Group

PowerShell command syntax

Add-DistributionGroupMember "<Distribution Group Name>" -Member <Identity>

PowerShell command Example

Add-DistributionGroupMember -Identity "Sales UK" -Member Bradp

Add a list of users to a specific Distribution Group

In the following section, we review examples of different scenarios, which their common denominator is that we need to add a “list of user” (array) to a specific Distribution Group.

This scenario can be described as – a relationship of – many to one.

Add a list of users to a specific Distribution Group

Scenario 1 – Add a “list of users” (multiple users) to Distribution Group | Import the “members list” from a CSV File

In this case, we want to add members to an existing Distribution Group, by importing the list of member’s from a CSV (Comma Separated Value) file.

In the current scenario, we export information about Office 365 users to a CSV file, by using the following PowerShell command:

PowerShell command Example

Get-mailbox | Select DisplayName,Alias,PrimarySmtpAddress |  Export-CSV c:\temp\Distribution-Groups-Members.csv –NoTypeInformation -Encoding utf8

The CSV file structure and “logic”
The CSV file structure is based upon the concept of – “column” and “rows.”

Using a CSV file as a source of information for Distribution Group members -01

In our example, the CSV file includes a list of users. Notice that each user (each row) can have a couple of “identities.”

For example, each user has the following identities: Display name, Alias and Primary E-mail address.

Using a CSV file as a source of information for Distribution Group members -02

In our example, we “relate” to the user identity, by “fetching” the user identity stored in the
column named PrimaryE-mailaddress.

Technically speaking, we can choose another user’s identity such as “DisplayName” or “Alias.”

Using a CSV file as a source of information for Distribution Group members -03

Note – You can download the CSV files that we use in the article for a demonstration purpose.

The PowerShell command structure.
The PowerShell script that we use is based on the following syntax:

Import Distribution Group members from a CSV File | Command structure

PowerShell command syntax

$<Variable> = Import-CSV <path>

ForEach ($<Variable> in $<Variable>)
{
Add-DistributionGroupMember -Identity "<DL NAME>" -Member $<Variable>.<Identity>
}

  • Part 1#3 – In the first part of the PowerShell command, we import the information (the list of users) from the CSV file. In our example, we “declare” about a
    variable named – $UsersList that will serve as a logical container for the content of the CSV file.
  • Part 2#3 – In the second part of the PowerShell command, we use the “ForEach” PowerShell statement, for executing a “loop process.”
    The PowerShell “loop process” use an additional variable named – $User.
  • The $User variable, serve as “temporary” container that will store a specific user identity for each “cycle” in the loop process.
  • Part 3#3 – this is the “actual PowerShell command” that we use (Add-DistributionGroupMember) for adding each of the users that appear in the CSV file to a specific Distribution Group.

In our example, the Distribution Group name is – “Marketing USA

Notice that we relate to the Distribution Group member by using a combination of the $User variable that is “attached” to the specific column in the CSV file named – PrimarySmtpAddress, by using the following convention $User.PrimarySmtpAddress.

In other words, we instruct the PowerShell loop process to use the PrimarySmtpAddress as the user identity.

Using a CSV file as a source of information for Distribution Group members -04

Import Distribution Group members from a CSV File

PowerShell command Example

$Userslist = Import-CSV C:\Temp\Distribution-Groups-Members.csv
ForEach ($User in $Userslist)
{
Add-DistributionGroupMember -Identity "Sales France" -Member $User.PrimarySmtpAddress
}

Scenario 2 – Add a “list of users” to Distribution Group | Users whom their department is equal to X.

In this scenario, our mission is to find all the users that their department is Sales, and these users to a Distribution Group named – “Sales worldwide”

In our example, the organization has a couple of sales departments, such as – Sales USA, Sales UK and so on.

To fulfill this requirement, we create the required list of users, by “executing” a PowerShell command that performs “filtered search.”

The PowerShell filtered search will look for all users, which their department is starting with the string “Sales*.”

We use the variable $SalesUsers for storing this information about the user’s list.

In the next step, we run a PowerShell loop process, which will use the information stored in the
variable – $SalesUsers and add each of the members stored in the $SalesUsers variable to the Distribution Group – Sales worldwide.

Add to Distribution Group all the users whom their department is Sales*

PowerShell command Example

$SalesUsers = Get-User | Where {$_.Department -like “Sales*”}
foreach ($User in $SalesUsers)
{
Add-DistributionGroupMember -Identity "Sales worldwide " -Member $User.name
}

Add a user (recipient) to Multiple Distribution Groups (bulk mode)

In the following section, we review examples of different scenarios, which their common denominator is – the need for adding a specific user to “many” or “multiple” (array) Distribution Group at the same time.

This scenario can be described as – a relationship of – one to many.

Add specific user as a member to multiple Distribution Groups

Scenario 1 | Add user (recipient) to multiple distribution groups | Manually providing the name of each Distribution Group.

In this section, I would like to review the scenario in which we want to add a specific user as a member to a list (array) of Distribution Groups

The information about the “destination Distribution Group” will be written as a part of the PowerShell command, and stored in a variable.

  • The user whom we want to add as a member to the various Distribution Group is – Brad.

The PowerShell command that we use, includes two parts:

  • Part 1#2 – in the first part of the PowerShell command, we define the PowerShell variable
    named – $GroupList, which serve as a “logical container” for the “array” of the Distribution Groups.
    In other words, define the list of the Distribution Group to which the user is going to be added.
  • Part 2#2 – In the second part of the PowerShell command, we use the “ForEach” PowerShell statement, for executing a “loop process.” The PowerShell “loop process” instructs PowerShell to:
    • “Get” the information stored in $GroupList
    • “Fetch” the name of the first Distribution Group in the list.
    • Add the user name as a member of the Distribution Group.

After the PowerShell loop, the process completes the task that relates to the “first Distribution Group” in the “list,” the PowerShell loop process starts the process all over with the “second Distribution Group” in the list until the “end” or the last name in the list.

Add user (recipient) to multiple distribution groups

PowerShell command syntax

$Variable = "<Distribution Group name>","<Distribution Group name>","<Distribution Group name>"
ForEach ($item in $Variable)
{Add-DistributionGroupMember -Identity $item –Member <Identity>}

PowerShell command Example

$DistributionGroupsList = "Sales UK","Sales USA","Sales Italy"
ForEach ($item in $DistributionGroupsList)
{
Add-DistributionGroupMember -Identity $item –Member Bradp 
–BypassSecurityGroupManagerCheck
}

Scenario 2 | Add user (recipient) to multiple distribution groups | Using the PowerShell command for getting a list of all existing Distribution Groups.

In this scenario, we want to add a specific user to all the existing Distribution Groups.

To be able to fulfill this requirement, we need to define an “array,” that include all the available Distribution Groups.

The array of Distribution Group will be defined in the following way:

We will use a variable named – $ALLDistributionGroups ,that will store the output from the PowerShell command – Get-Distribution group -resultsize unlimited.
In the second part of the PowerShell command, we use the “ForEach” PowerShell statement, for executing a “loop process” on the results (the array the include the list of existing Distribution Groups).

An example of the PowerShell syntax that we use is:

Add user (recipient) to multiple distribution groups

PowerShell command Example

$ALLDistributionGroups = Get-Distributiongroup -resultsize unlimited
ForEach ($item in $ALLDistributionGroups)
{
Add-DistributionGroupMember -Identity $item –Member Bradp
}

Scenario 3 | Add user (recipient) to multiple distribution groups | read the information about the Distribution Group list from a CSV file.

In this example, the information about the “list of Distribution Groups,” is stored in a CSV file. Technically speaking, the CSV file can include many additional “information columns,” beside of the specific column that includes the Distribution Groups names.

In our specific example, the column that includes the Distribution Group names named – “GroupName.”

It’s important to mention that the column header name is not a “predefined name” or a mandatory name.

Instead, the column name is just an arbitrary name, that we choose. The only “restriction” is that the name of the header will not contain any spaces.

The specific column that contain the names of the Distribution Groups

Note – You can download the CSV files that we use in the article for a demonstration purpose.
  • In the first part of the PowerShell command, we define a variable named – $DistributionGroupsList, that stores the content of the CSV file (the CSV file that contains the list of the Distribution Groups).
  • The second part of the PowerShell command will “access” the information stored in the
    column – GroupName.

Add user to multiple distribution groups listed in a CSV file

PowerShell command Example

$DistributionGroupsList = Import-CSV C:\Temp\Distribution-Group-list.csv
ForEach ($Group in $DistributionGroupsList)
{
Add-DistributionGroupMember -Identity $Group.GroupName -Member Brad
}

Scenario 4 | Add user (recipient) to multiple distribution groups | get a list of Distribution Group that was created in the last X hours.

In the following example, we want to add the user Brad as a member of all the Distribution Groups, that was created in the last 48 hours.

  • Part 1#2 – in the first part of the PowerShell command, we define the PowerShell variable
    named – $AllNewDistributionGroups.
    The $AllNewDistributionGroups variable will store the output from a PowerShell query that “fetch” all the Distribution Group that their “creation time” is less or equal to the last 40 hours.
  • Part 2#2 – In the second part of the PowerShell command, we use the “ForEach” PowerShell statement, for executing a “loop process” on the results.
    The PowerShell command will relate to each of the Distribution Group by using the $Group variable that will use the “name” property of the Distribution Group object.

Add user to distribution groups that was created in the last 48 hours

PowerShell command Example

$AllNewDistributionGroups  = Get-DistributionGroup | Where {$_.WhenCreated –ge ((Get-Date).AddHours(-48))}
ForEach ($Group in $AllNewDistributionGroups)
{
Add-DistributionGroupMember -Identity $Group.name –Member Bradp
}

Scenario 5 – Add user to Distribution Group only if the user is not already a member of the Distribution Group

In the following scenario, we wish to verify if a specific user is a member of a Distribution Group, if the user is not a member of the Distribution Group, we want to add the user as a member of the Distribution Group.

Scenario description

  • The user whom we want to check is – Bob.
  • The Distribution Group name is – Sales France.

To be able to fulfill this requirement, we can use the following PowerShell command

PowerShell command Example

$Recipient = Get-Recipient -Identity bob
$Group = get-DistributionGroup -Identity 'Sales France'
$GetMember = Get-DistributionGroupMember $Group.name
if ($Group.name -notcontains $Recipient.Name)
{Add-DistributionGroupMember -Identity $Group.Name -Member $Recipient.Name}

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

Please rate this

The post Manage Distribution Group using PowerShell in Office 365 | Adding members to existing Distribution Group | Part 3#5 5/5 (1) appeared first on o365info.com.

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

$
0
0

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

Get-DistributionGroup

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

Get-DistributionGroupMember "<Distribution Group Name>"

PowerShell command Example

Get-DistributionGroupMember "Sales France"

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

Get-DistributionGroupMember IT | Sort -Property DisplayName | Select DisplayName, Alias, Department

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

(Get-DistributionGroupMember "IT").Count

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

Get-DistributionGroup | Where {$_.emailaddresses –like <"*Domain Name*">} | FT -Property Name,Alias,EmailAddresses -Autosize

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

PowerShell command Example

Get-DistributionGroup | Where {$_.emailaddresses –like "*o365info.com*"} | FT -Property Name,Alias,EmailAddresses -Autosize

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-DistributionGroup | Where {$_.WhenCreated –ge ((Get-Date).Adddays(-14))} | FT DisplayName,WhenCreated

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

PowerShell command Example

Get-DistributionGroup | Where {$_.WhenCreated –le ((Get-Date). Adddays (-14))} | FT DisplayName,WhenCreated

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

Get-DistributionGroup | Where {$_.ManagedBy  -like “*adele*”} | FT DisplayName,ManagedBy

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

Get-DistributionGroup | FT DisplayName,ModeratedBy

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

Get-DistributionGroup | Where {$_.ModeratedBy -notlike “$null”} | FT DisplayName,ManagedBy

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

Get-DistributionGroup | Where {$_.IsDirSynced  -eq $true} | FT DisplayName, IsDirSynced

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

Get-DistributionGroup | Where {$_.RequireSenderAuthenticationEnabled -eq $True} | FT DisplayName,RequireSenderAuthenticationEnabled

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-DistributionGroup | Where {$_.RequireSenderAuthenticationEnabled -eq $False } | FT DisplayName,RequireSenderAuthenticationEnabled

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

$User = read-host “User Name"
$UserDName = (Get-Mailbox $User).name
"The User " + $User + " is a member of the following Distribution Groups:"
ForEach ($DistributionGroup in Get-Distributiongroup -resultsize unlimited)
{
if ((Get-Distributiongroupmember $DistributionGroup.identity | select -expand name) -contains $UserDName)
{$DistributionGroup.name}
}

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

Get-DistributionGroup | Out-File c:\temp\DistributionGroups.TXT

Export information to CSV FilePowerShell command Example

Get-DistributionGroup | Export-CSV c:\temp\DistributionGroups.CSV –NoTypeInformation -Encoding UTF8

Export information to HTML File

PowerShell command Example

Get-DistributionGroup | ConvertTo-Html c:\temp\DistributionGroups.HTML

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

$Groups = Get-DistributionGroup -ResultSize Unlimited 
Foreach ($Group in $Groups) 
{     
	$Members = Get-DistributionGroupMember -Identity $($Group.PrimarySmtpAddress) 
	Foreach ($Member in $Members) 
	{ 
		Out-File -FilePath c:\temp\DistributionGroupMember.csv -InputObject "$($Group.DisplayName),$($Member.DisplayName),$($Member.PrimarySMTPAddress)" -Encoding UTF8 -append 
	} 
}

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

Please rate this

The post Manage Distribution Group using PowerShell in Office 365 | view and export information about Distribution Group | Part 4#5 5/5 (2) appeared first on o365info.com.

Manage Distribution Group using PowerShell in Office 365 | Delete Distribution Group and members | Convert Distribution Group | Part 5#5 5/5 (2)

$
0
0
The current article is fifth and the last article in our 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. Distribution Group management tasks that relate to deletion of Distribution Group or deletion of members from a Distribution Group.
  2. Additional Distribution Group posable management task which I describe as – “Playing with Distribution Group.” In this section, we review two “tricks” that enable us to bypass inherent limitations of a Distribution Group.
    • Converting Office 365 distribution Group to Security Group and vice versa.
    • Assign “Full Access” permissions to Distribution Group + use AutoMapping option.

1. Delete Distribution Group + Remove members from Distribution Group

In the following section, we review the Distribution Group management task that relates to a “deletion” or a “removal” of:

  1. Distribution Group – for this purpose, we use the PowerShell
    cmdlets – Remove-DistributionGroup
  2. A specific member\s from a Distribution Group -for this purpose, we use the PowerShell
    cmdlets – Remove-DistributionGroupMember

Delete (Remove) a Distribution Group

Delete (Remove) a Distribution Group

To delete an existing Distribution Group, we use the following PowerShell command:

PowerShell command syntax

Remove-DistributionGroup "<Distribution Group Name>"

PowerShell command Example

Remove-DistributionGroup "Sales USA "

Note – at the current time, Office 365 doesn’t provide the option of restoring a deleted Distribution Group. So, before to “rush” to the distorted existing Distribution Group, think twice!
recover / restore deleted office 365 group

Remove a member from a Distribution Group

To be able to remove a specific member or members from a Distribution Group, we use the following PowerShell syntax:

PowerShell command syntax

Remove-DistributionGroupMember -Identity "<Distribution Group name>" -Member "<Member name>"

PowerShell command Example

Remove-DistributionGroupMember -Identity "Sales USA" -Member "Bob"

Remove user from all the Distribution Groups which he is a member in

In the following scenario, we want to fulfill the following requirement:

We want to get a list of all the Distribution Group, which a specific user is a member of.

Then, we want to remove the user from each Distribution Group, which he is a member.

PowerShell command Example

$DistributionGroups = Get-Distributiongroup -resultsize unlimited
$UserDName = read-host “Enter User Name"
$UserDName = (Get-Mailbox $User).name
"Searching which groups " + $User + " is a member of and removing membership..."
ForEach ($Group in $DistributionGroups)
{
if ((Get-Distributiongroupmember $Group.Name | select -expand name) -contains $UserDName)
{
write-host "Removing user from group '$Group'"
Remove-DistributionGroupMember -Identity "$Group" -Member "$UserDName" -Confirm:$false
}
}

Remove all members from a Distribution Group

In the following scenario, we wish to “clean” a specific Distribution Group from all the members that are contained in the Distribution Group.

In other words, we want to “bulk removes” all existing members.

To be able to fulfill this requirement, we can use the following PowerShell syntax:

PowerShell command Example

$DistributionGroupMember = Get-DistributionGroupMember "IT"
ForEach ($member in $DistributionGroupMember)
{
Remove-DistributionGroupMember -Identity IT –Member $member.name -Confirm:$false
}

How to convert Distribution Group into a security group | Tips and tricks

Let’s start with the simple fact that at the current time, Office 365 and Exchange Online environment doesn’t provide an option for converting existing Distribution Group to a security group (the most accurate term is a mail-enabled security group).

I use the term “convert” for describing a process that can partially simulate the process of converting group from type X to type Y.

The solution that I offer is based on the following steps:

  1. Create a NEW security Distribution Group.
  2. Copy all the members from the existing Distribution Group to the “destination” security Distribution Group.
  3. Delete \ Remove the Distribution Group

It’s important to me to mention that, the “trick” in which we copy the numbers from one type of group (the Distribution Group) to the “other group” (security group) is not providing a “full solution” because, the group properties such as mail permissions or other Distribution Group properties are not “migrated” to the new group.

In the following section, I provide two “flavor” of the PowerShell script that will implement the “group conversation process.”

The first example implements a very basic process that copies the Distribution Group member to the NEW group.

Copy members from Distribution Group to a security group

PowerShell command Example

$Members = Get-DistributionGroupMember -id "<Name of the source group>"
ForEach ($Member in $Members)
{
Add-DistributionGroupMember -Identity "<Name of the destination security group>" -Member $Member.name
}

The second example, provides more “sophisticated operation” and performs the following tasks:

  • Creating the NEW “destination security group”
  • Define a group name that is based on the following naming convention – the name of the Distribution Group + the string “NEW”.
  • Copy the remember from the Distribution Group to a temporary variable.
  • Copy the Distribution Group members to the “NEW security group.”

Variation 2

PowerShell command Example

$DistributionGroupName = Read-Host -prompt "Type the Distribution Group name"

$Members = Get-DistributionGroupMember -id $DistributionGroupName
New-DistributionGroup -Name $DistributionGroupName-NEW -Type Security
ForEach ($Member in $Members)
{
Write-host “NEW security group named - $DistributionGroupName-NEW created!”
Write-host “The security group - $DistributionGroupName-NEW contain all the members of the Distribution Group named - $DistributionGroupName”
Add-DistributionGroupMember -Identity "$DistributionGroupName-NEW" -Member $Member.name
}

Assign “Full Access” permissions to Distribution Group + use AutoMapping option | Tips and tricks

In the following section, we use a trick, that will enable us to provide Full Access permissions to each of the members who include in a specific Distribution Group.

We will not get into a very detailed explanation of the possible permission’s matrix in Exchange and Exchange Online base environment, but shortly explain that technically, we cannot provide permissions to Distribution Group on “other objects” such as Exchange Online mailbox because Distribution Group is not a “security-enabled object.”

Note – if you want to read more detailed information about the subject of “Full access permissions” in the Exchange Online environment, you can read the article – Full Access Mailbox permission – Everything You Always Wanted to Know About But Were Afraid to Ask part 1/3

In other words, technically, we cannot fulfill the requirement of providing Full access permissions to a Distribution Group on the other Exchange mailbox.

The trick that we use, bypass this limitation in the following way:

  • We get a list of each member in a specific Distribution Group
  • We store this information temporarily in a variable
  • We take the information stored in the variable (the Distribution Group members) and assign Full access permission for each of the members on the “destination mailbox.”
  • In case that we assign the Full access permission “directly” to a specific Exchange user account, the feature of “AutoMap” will be activated and after the Full Access permissions are assigned, the “destination mailbox” will automatically appear in the user Outlook mail profile.

Extract Distribution Group member’s, and assign Full access permissions for each group member

PowerShell command Syntax

$DistributionGroupName = Get-DistributionGroupMember "<Distribution Group name>"
ForEach ($Member in $DistributionGroupName)
{
Add-MailboxPermission -Identity "<mailbox identity>“ -User $Member.name -AccessRights ‘FullAccess’ -InheritanceType all
}

  • In our example, the Distribution Group name is – Sales France
  • The destination mailbox meaning the mailbox which we want to provide the Full access permissions is the mailbox of a user named – Brad

Extract Distribution Group member’s, and assign Full access permissions for each group member

PowerShell command Example

$DistributionGroupName = Get-DistributionGroupMember "Sales France"
ForEach ($Member in $DistributionGroupName)
{
Add-MailboxPermission -Identity "Bradp"  -User $Member.name -AccessRights ‘FullAccess’ -InheritanceType all
}

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

Please rate this

The post Manage Distribution Group using PowerShell in Office 365 | Delete Distribution Group and members | Convert Distribution Group | Part 5#5 5/5 (2) appeared first on o365info.com.

Assign Full access permissions to Exchange Online mailbox 5/5 (1)

$
0
0
In the current article, we review how to add Full Access permissions to a specific mailbox in an Office 365 based environment.

The assignment of the “Full Access mailbox permissions” is a simple operation, that is implemented by using the Exchange Online web-based management interface.

The other half of the Full Access permission’s process is related, to the way that the user who has the permissions view the “destination Mailbox.”

In the second part of the article, we will review how Outlook and OWA mail client view a mailbox which the user has Full permissions on it.

Our scenario description

In our example, we would like to assign a user named – Chris, Full Access permissions on Frank mailbox.

After we provide the required permissions, we will need to verify the Chris can view Frank mailbox when he uses Outlook + OWA mail clients.

The required scenario of Full access permissions

Assigned Full Access permissions to the Exchange Online mailbox

To assign the required Full Access permissions, log in to Exchange Online admin center

  • On the left menu bar, select the menu – recipient (number 1).
  • On the Top menu bar, select the menu – mailboxes (number 2).
  • In the mailbox list, select + double-click on the specific recipient whom you want to assign Full Access permissions on his mailbox. In our example, the recipient who will “share his mailbox” with another user is – Frank (number 3).

Assign Full access permissions to Exchange Online mailbox -01

  • In the “Mailbox properties” window, select the menu – Mailbox delegation (number 1).
  • Scroll down to the “Full Access” section
  • Click on the plus icon (number 2).

Assign Full access permissions to Exchange Online mailbox -02

  • From the recipient list, select the specific recipient who will have the Full Access permissions. In our example, Chris is the recipient who will have Full access permissions on the Frank mailbox (number 1).
  • Click add -> (number 2).
  • Click OK (number 3).

Assign Full access permissions to Exchange Online mailbox -03

In the following screenshot, we can see that under the “Full Access” section, Chris appear as the user who has Full Access permissions on Frank mailbox.

  • Click Save

Assign Full access permissions to Exchange Online mailbox -04

How Outlook and OWA mail client view a mailbox which the user has Full permissions on it?.

After we have been complete the task of assigning the Full Access permissions, the next step is related to the way that the user who has the permissions can use for accessing the “destination mailbox.”

The “way” depends on the mail client that you use because Outlook client is behaving differently from OWA mail client regarding the subject of viewing the “destination mailbox.”

How to access your mailbox you have Full access permissions - Outlook

The Full Access permissions using a special feature named – Automapping.

The Automapping feature automatically the “destination mailbox” to the Outlook mail profile without any need for additional configuration.

In our example, after we assign the Full access permissions to Chris on Frank mailbox, Frank mailbox will be added automatically to the Chris Outlook mail profile.

In the following screenshot, we can see the when Chris open his Outlook mail profile, the additional mailbox was added to his Outlook mail profile.

How to access your mailbox you have Full access permissions - Outlook

How to access your mailbox you have Full access permissions – OWA

In case that a user has Full Access permissions to another user mailbox and he uses OWA mail client, he needs to implement a short procedure to add the “additional mailbox” to his OWA mail profile.

How to access your mailbox you have Full access permissions - owa-01

  • Right click on the “recipient name.” In our example, Chris

How to access your mailbox you have Full access permissions - owa-02

  • Select the menu – Add share folder…

How to access your mailbox you have Full access permissions - owa-03

  • In the search box, Active Directory the name of the recipient whom you want to add his mailbox.

How to access your mailbox you have Full access permissions - owa-04

  • Click Add

How to access your mailbox you have Full access permissions - owa-05

In the following screenshot, we can see the when Chris open his Outlook mail profile, the additional mailbox was added to his Outlook mail profile.

How to access your mailbox you have Full access permissions - owa-06


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

Please rate this

The post Assign Full access permissions to Exchange Online mailbox 5/5 (1) appeared first on o365info.com.


Creating a loop through an array Using the “ForEach” PowerShell command | Basic introduction | Part 1#2 5/5 (4)

$
0
0
In the current article, I would like to provide a basic introduction to the concept of “Array” and the “ForEach statement”, in PowerShell based environment (especially in Office 365 and Exchange Online based environment).

The Creating a loop through an array Using the “ForEach” PowerShell article series, including the following articles:

The combination of – Arrays and the Loop process (which implemented by using the PowerShell “ForEach statement”), is a very powerful tool, that enables us to perform a bulk administrative task on multiple objects in “one click”.

The “problem” (or the challenge if we want to use a more politically correct word) is that most of the Exchange or Office 365 administrators are a little scary from the “PowerShell monster”, and especially more “complex scenario” in which we need to use a PowerShell command that includes more then one line.

The PowerShell monster

The good news is that If you’re ready to invest a little time by reading the following two articles, you will find that the terms “Array”, Loop process and “ForEach statement” are not so scary.

After you will learn how to “enroll” this tools, you will get a very useful tool that could improve and optimize your day to day administrative tasks!

Generally speaking, to the concept of the “Array” are relevant to any programming or script Language but as mentioned, in the current article, the examples are related to Office 365 environment.

What should I learn about “arrays”?

In PowerShell environment, we use the concept of “Arrays” many times, whether we know it or not. In case that we want to understand better many of the PowerShell command syntax examples, and to effectively utilize “PowerShell,” we should have a basic understating of the “arrays” concept.

What is the meaning of Array?

Let’s start with a formal definition of the term “Array” as it appears in Wikipedia:

In computer science, an array type is a data type that is meant to describe a collection of elements (values or variables), each selected by one or more indices (identifying keys) that can be computed at run time by the program. Such a collection is usually called an array variable, array value, or simply an array.

By analogy with the mathematical concepts of vector and matrix, array types with one and two indices are often called vector type and matrix type, respectively.

[source of information – Array data type]

In simple words, the term “Array” define a group or a list of “objects” that we can “address” or relate to when using a PowerShell command.

What is the meaning of array

The Array considers as a collection of objects or other term -collections of members.

Theoretically, the Array can be empty or, contain zero members, but most of the time, we use the “Array” for grouping or “binding” one or more “objects.”

What is the meaning of array members

The next question that can appear is – what are these “objects” or who are these “members”?

Array contain what

The terms “objects” or “member” is a very general term that we use for describing different types of “entities” that we want to address.

In PowerShell based environment, there is a multiple of examples to the term “objects.”

For example, an object can be considered as Exchange mailbox, Office 365 users, operating system process or even a “row” in a file.

An example of array members

An Array can contain 100% of a specific type of object or, a “subset” of specific objects with a specific character or a specific property.

For example,

The PowerShell command – Get-Mailbox, will get a list of all Exchange mailboxes.
In other words, we can say that the PowerShell command – Get-Mailbox, creates an Array that contains all the objects that considered as “mailbox object”.

The PowerShell command –

Get-Mailbox | Where {$_.RecipientTypeDetails -eq “UserMailbox”

will get a list of all Exchange Online mailboxes that considered as “user mailboxes.”

In other words, in this case, the Array that created contain only a specific subset or a “group” of Exchange mailboxes, that have a specific property (RecipientTypeDetails), and considered as – “User mailbox.”

How does Array is created?

The “Array content” can be created by

Another interesting question that we can ask is – what are the methods that we can use for creating an “Array”?

There are various ways for “creating” an Array.

  1. Using basic PowerShell command – for example, each PowerShell cmdlets that start with the prefix “Get,” create an Array.
  2. Information that stored in a file in a specific format such as CSV file, can also be considered as an “Array”. When we need to access information that stored in a CSV file, each “row” in the CSV file, considered as “array members,” and each column in the CSV file will be considered as a “member property”.
  3. Using Group – although we don’t use to relate to a “Group” as an “Array,” Group is actually an array. A “group” serve as a logical container that contains Group members, and this is the exact definition of Array.
  4. Writing manually each member – an additional method for creating “Array” is simply implemented by manually writing each of the Array members. For example, when we assign permission to the specific user mailbox, we can assign the permissions for multiple users (Array). The creation of the “Array” is implemented by writing down, each of the users (members) separated by the comma character.

PowerShell command as a tool for creating arrays

In this section, I would like to relate to the PowerShell command prefix “Get” as one of our main methods for creating an “Array.”

Each time we run a PowerShell command with the prefix “Get,” we are actually asking from PowerShell to create for as an “Array”.

PowerShell Get command serve as A utility for creating Array

By default, the “Array content” will be displayed by the PowerShell command on the PowerShell console, but it’s important to emphasize that the first “action” that is implemented by PowerShell command is – storing the “Array data” in the computer RAM, and only then, copy the information to the PowerShell console.

Beside of viewing the “Array data” in the PowerShell console, we can use the Array information that is stored in the RAM and choose what we want to “do” with the data.

For example, we can export the array information to a file, “pipe” to information to another PowerShell command and so on.

An example, creating an array by using the PowerShell Get-Mailbox command.

Exchange infrastructure includes dozens, even hundreds of different objects type such as Exchange recipients, groups, connectors, mailboxes and so on.

When we use a PowerShell cmdlets such as – Get-Mailbox, we are asking from Exchange Online to provide us information about a very specific object type – “Exchange mailboxes.”

When we write, the PowerShell Get-Mailbox, and “hit” the Enter key, PowerShell is automatically creating an “array space”, and “fill in” the array store with an information about all the existing Exchange mailboxes.

Fetch specific objects from an Array -01

An additional example of creating an array by using PowerShell

Another example of an Array that we create by using a PowerShell command, can be an example in which we use the following PowerShell command that create a filtered search such as:

Get-User | Where {$_.Title -eq “Administrator”}

In this case, we “ask” from Exchange to provide us a list of all Exchange users (an array of Exchange Online users), but add additional Filter, that includes the condition – “fetch information” only if the user title is – Administrator.

Fetch specific objects from an Array -02


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

Please rate this

The post Creating a loop through an array Using the “ForEach” PowerShell command | Basic introduction | Part 1#2 5/5 (4) appeared first on o365info.com.

Creating a Loop through an array Using the “ForEach” statement and variables | PowerShell environment| Part 2#2 5/5 (2)

$
0
0
The current article, is the continuation of the former article, in which we provide a basic introduction to the subject of the way that we write a PowerShell command, the loop through an array using the “ForEach” statement.

The Creating a loop through an array Using the “ForEach” PowerShell article series, including the following articles:

Using a PowerShell variable

what is Variable

If we want to simplify the explanation of the term “variable,” we can relate to the variable component” as a “logical container that holds “data.”

PowerShell variable -The purpose

Most of the time, the “data” stored in the variable, can be considered as an “Array data”.

The “variable,” can be considered as an “essential component,” that is used quite often, when using a PowerShell “ForEach statement” and arrays.

Using variable – The Flow of events

When using a PowerShell variable, the following phases or steps are implemented:

  • Step 1#3 – in the first phase, we declare the variable, and the “variable store” is empty.
  • Step 2#3 – In the second phase, we store information in the “variable store,” by “redirecting” the output of PowerShell “Get” commands.
  • Step 3#3 – Later, we use an additional PowerShell command\s, that “access” the information stored in the variable, and “do something” with this information.

The variable syntax in PowerShell environment.

The variable “syntax” is written in the following way:

  • Part 1#3 – We use the “$” sign for “declaring” a variable.
  • Part 2#3 – Then, we define the variable name. The variable name is an arbitrary name, whom we choose. The best practice is to choose a “meaningful” variable name. Variable names are not case-sensitive. Variable names can include spaces and special characters, but these are difficult to use and should be avoided.
  • Part 3#3 – Write the specific “PowerShell Get” command, that we use for “fetching data” about specific objects. The output from the PowerShell command, will be stored in the variable.

PowerShell variable -Naming convention-01

An example of variable syntax could be – $ExchangeMailboxes = Get-Mailbox

In this scenario, we defined a variable named- $ExchangeMailboxes ,that will use for storing the information that we get from the PowerShell command –
Get-Mailbox.

PowerShell variable -Naming convention-02

Using a PowerShell “ForEach” statement + Array

One of the most distinct advantages of implementing management tasks by using PowerShell, is the ability to perform a “Bulk operation” meaning, a process that will be executed on a “group” (Array) of objects.

The ability to run a specific task on array members is implemented many times by using a combination of the “ForEach” PowerShell statement + a variable that store the Array data (Array member’s).

We use the ForEach PowerShell statement for implementing the following flow:

  1. “Scanning” the Array content.
  2. Locate the first member in the array.
  3. Run a specific PowerShell command on the Array member (“do something”).
  4. Start the process all over again, by access the Array store, fetching the second member in the Array, run the requested PowerShell command and so on.

This loop process will stop after the “ForEach PowerShell statement’” locates the “last member” in the Array.

Running a PowerShell ForEach statement

In the following diagram, we can see an example of a PowerShell command
that includes the “ForEach PowerShell statement” + PowerShell variables.

  • Part 1#3 – in this part, we declare the name of the variable, and “charge” the “variable store” with the result of a “Get” PowerShell command.
  • Part 2#3 – in this part, we start the “ForEach PowerShell stamen” + declare the name of additional variable, that is used for representing a specific member in the Array.
  • Part 3#3 – in this part (that start with the curly brackets), we define the specific PowerShell command, that is “executed” separately for each member in the Array. This is the “Do Something” part. When using a Loop statement, the specific PowerShell command is written between curly brackets.

PowerShell ForEach statement syntax - The parts

How to address a member in the Array?

As we know, an Array is a collection of members.
When we use a PowerShell command that uses “ForEach PowerShell statement,” we wish to address or reference each of the members in the array, and “apply” a specific PowerShell command to each of the specific members.

Array and Array members

Technically speaking, there are a couple of methods that we can use to relate to the “Array member object.”

In the current article, I would like to review the method, in which we use an additional variable, that represents the “member object.”

The ForEach PowerShell statement, “knows” how access the “Array space” (represented by the “Array variable”), and loop through the Array.

In each Loop, the ForEach PowerShell statement “pull” a specific member from the Array (represented by the “Member variable”), run the required PowerShell command, and continue to the “next Array member.”

The name of the variable that represents the array member, is just an arbitrary name, whom we choose.

The best practice is to choose a meaningful variable name, which helps us to easily distinguish between the “member” and the “Array.”

In the following diagram, we can see the structure of the “ForEach PowerShell statement” command, in which we define the Array and the member in the Array, by using two different variables.

In our example, the variable $Mailbox represent each member in the array and the variable $ExchangeMailboxes represent the Array himself.

How to address a member in the Array

To be able to demonstrate the concept of Variable and Array, let’s use the following two examples:

Example 1 – view a specific array member

In the next example, we use a Variable named $ExchangeMailboxes, for storing the array that is created via the use of the PowerShell command- Get-mailbox.

The “complete PowerShell sentence” is-

$ExchangeMailboxes = Get-Mailbox

In this phase, we have a Variable that contains one or more member (Exchange Online mailboxes). Theoretically, we cannot “know” what is stored in the “Variable space.”

To be able to view the first Array member stored in the Variable $ExchangeMailboxes, we can use the following PowerShell command:

$ExchangeMailboxes[0]

To view the second Array member, stored in the Variable $ExchangeMailboxes

$ExchangeMailboxes[1]

And so on.

PowerShell console output example

PS C:\script> $ExchangeMailboxes = Get-Mailbox

PS C:\script> $ExchangeMailboxes[0]

Name Alias ServerName ProhibitSendQuota

---- ----- ---------- -----------------

Adele Adele amxpr05mb0646 49.5 GB (53,150,220,288 bytes)

PS C:\script> $ExchangeMailboxes[1]

Name Alias ServerName ProhibitSendQuota

---- ----- ---------- -----------------

admin_3a5bb52c62 Bob he1pr05mb1369 49.5 GB (53,150,220,288 bytes)

Example 2 – Writing a PowerShell loop statement the display each array member

The following, example has no “real purpose” besides of the purpose of demonstrating how to Loop statement is executed for each of the Array members.

In this example, we “ask” from PowerShell to fetch each of the Array members that are stored in the Variable $ExchangeMailboxes and write on the PowerShell console screen a notification that uses the following syntax:
This is one of the array members – “(Exchange mailbox)” + <Array member name>

PowerShell command example

$ExchangeMailboxes = Get-Mailbox
ForEach ($Mailbox in $ExchangeMailboxes)
{
Write-host This is one of the array members - "(Exchange mailbox)" - $Mailbox
}

PowerShell console output example

This is one of the array members - Exchange mailbox - Adele

This is one of the array members - Exchange mailbox - Alice Good

This is one of the array members - Exchange mailbox - Alicia Keys

This is one of the array members - Exchange mailbox - Angelina Jolie

This is one of the array members - Exchange mailbox - Aretha Franklin

This is one of the array members - Exchange mailbox - Beatles the

This is one of the array members - Exchange mailbox - Beyonce

This is one of the array members - Exchange mailbox - Billy

This is one of the array members - Exchange mailbox - Bob Marley

How to specify the identity of a specific Array member?

In this section, I would like to relate to the subject of – How to specify the identity of a specific Array member?

As mentioned, we want that a specific PowerShell command will run over each member of the Array.

To enable PowerShell to perform this task, we need to use a method which will help PowerShell to “relate” to each of the members separately. In other words, we need to “tell” PowerShell, what is the “identity” of each member in the Array.,

To specify the identity of a member in an Array in PowerShell environment, we use the following syntax:

The variable name that represents the “member object” + the “dot character” + one of the object properties that represent object identity.

Sound confusing and difficult to understand?

The only solution that I know of is – reading the provided information and the examples over and over until you are able to see the “complete picture.”

How to specify the identity of a specific Array member -01

In the following diagram, we can see an example of the syntax that we use for relating to a specific member in the Array.

In our example, the variable that we use for representing Array member is – $Mailbox and the “object identity property” that we use is – “DisplayName.”

How to specify the identity of a specific Array member -02

Object identity” and “identity property”

This brings us to the next question – what is the meaning of “object identity,” and what is the meaning of “identity property”?

The answer is that each “PowerShell object,” has an “identity” in a similar way that each of us has an identity.

To make the issue even more complicated, each PowerShell object can have multiple identities like each of us can have multiple identities such as – private name, Nickname, Social security number and so on.

What is the meaning of Object identity property -03

In the following diagram, we can see an example of all the available identities of Exchange mailbox in the Exchange Online based environment.

In case that you get a “headache” from the variety of the multiple identities, it’s OK!

In reality, we don’t use all the types of these “identities” but instead, only a specific set of identities that are commonly used.

The multiple Object identities - Exchange Online mailbox -04

Array members and the two common types of relationships

In this section, I would like to relate to the subject which I describe as “Array members and the two common types of relationships.”

Technically speaking, we can define four types of relationships between objects:

  1. One to one
  2. One to many
  3. Many to one
  4. Many to many

To be able to define “one to one” relationship, we don’t need to use an Array and “ForEach” PowerShell statement.”

Regarding the relationships which I describe as -“Many to Many,” I prefer not to relate to this type of relationship in the current article because it could become a little complicated.

In many scenarios, the most common relationships that we deal with are, the relationships which can be described as – one to many or many to one.

Array members and the two common type of relationships

One to many relationships – example

The relationship which defined as “One to many,” relate to a scenario, in which we want to enable a specific object (one) to “impact” multiple objects (Array).

In other words, enable a specific object to “do something” for each member in the Array of objects.

Array members and two type of relationships -One to many relationships -02

To be able to demonstrate such relationship, let’s use the administrative task of assigning permissions.

For example, John is the Exchange Online administrator. We wish to assign John, Full Access permission on each of the existing Exchange Online mailboxes.

  • In our example, that “Array” include all the Exchange Online mailboxes
  • Each Exchange Online mailbox considers as a Member in the Array.
  • John represents the “One” in the current relationship.
  • Exchange Online mailboxes represent the “Many” in the current relationship.

Many to one relationship – example

The relationship which defined as “Many to one,” relate to a scenario, in which we want to enable multiple objects (Many) to “impact” a specific or an individual object (one).

In other words, enable a Group of objects (multiple objects) to “do something” on a specific object.

To be able to demonstrate such relationship, let’s use the administrative task of assigning permissions.

For example, we would like to assign Full Access permissions to all the users who “belong” to the IT group, on the “Help Desk mailbox” (one) that serves as a mailbox for Helpdesk tickets.

  • In our example, the “Array” include all the IT members.
  • Each IT user considers as a Member in the Array.
  • The IT members represent the “Many” in the current relationship.
  • The “Help Desk mailbox” represents the “One” in the current relationship.

Array members and two type of relationships -Many to One relationships -03

Using PowerShell Loop statement + variables + define the two-common type of relationships

In this section, I would like to “rap” couple of subjects that we have reviewed, up until now, so we will be able to understand better the “whole picture.”

Using a PowerShell ForEach statement example – One to Many relationship’s examples

In the current section, we demonstrate a relationship which described as “One to Many.”

Scenario description

In our scenario, John is the Exchange Administrator.
We want to assign John Full access permissions on all the existing Exchange Online mailboxes.

PowerShell ForEach statement example - One to many relationships - 01

To be able to fulfill this requirement, we create a PowerShell Loop command, that includes the following parts:

Part 1#3 – In this part, we define a variable named – $ExchangeMailboxes, that will “hold” the output from the PowerShell command – Get-Mailbox.

The specified PowerShell command will get the “list” of all existing Exchange Online mailboxes.

$ExchangeMailboxes = Get-Mailbox

Part 2#3 – In this part, we define an additional variable named- $Mailbox, that is used for representing each of the members in the “Exchange mailbox Array” (the information stored in the variable – $ExchangeMailboxes).

ForEach ($Mailbox in $ExchangeMailboxes)

PowerShell ForEach statement example - One to many relationships - 02

Part 3#3 – In this part, we define the PowerShell command that will assign the user “John” a Full Access permission for each of the Exchange Online mailboxes.

Add-MailboxPermission –identity $Varibale.<Identity> -user <Identity> -AccessRights FullAccess

Referencing each array member identity

Notice the syntax that we use for referencing each of the Array members (each of the Exchange Online mailbox) identity.

The syntax that we use is – $Mailbox.DisplayName

The identity of each member is “written,” by using the variable name that temporary hold each of the members in the array ($Mailbox) + a specific “identity” property.

In our example, we use the “DisplayName” as the identity property.

The “combination” of these two parts, enable us to “identify” each of the Array members individually in the Loop process that is executed by the “ForEach PowerShell statement.”

PowerShell ForEach statement example - One to many relationships - 03

sing the PowerShell ForEach statement example – Many to One relationship example

In the current section, we demonstrate a relationship which described as “Many to One.”

Scenario description

The IT uses a shared mailbox named – HelpDesk, that serves for storing help desk tickets that the organization user open.

We would like to enable each of the IT members, to have a Full Access permission to the shared mailbox named – HelpDesk.

PowerShell ForEach statement example - Many to One relationships -01

Part 1#3 – In this part, we define a variable named – $ITMembers, that will “hold” the output from the PowerShell command – Get-User | Where {$_.Title -eq “Administrator”}

The specified PowerShell command will get the “list” of all existing users, which their title contains the value – “Administrator”.

$ITMembers = Get-User | Where {$_.Title -eq “Administrator”}

Part 2#3 – In this part, we define an additional variable named- $User, that is used for representing each of the members in the “IT array” (the information stored in the variable – $ITMembers).

ForEach ($User in $ITMembers)

Part 3#3 – In this part, we define the PowerShell command that will assign each of the IT Members, Full Access permission on the “Helpdesk mailbox”.

Add-MailboxPermission –identity <Identity> -user $user.<Identity> -AccessRights FullAccess

PowerShell ForEach statement example - Many to One relationships -02

Referencing each array member identity

Notice the syntax that we use for referencing each of the Array members (each of the IT members) identity.

The syntax that we use is – $User.Alias

The identity of each member in the Array, is “written,” by using the variable name that temporary hold each of the members in the array ($User) + a specific “identity property”.

In our example, we use the “Alias” as the identity property.

The “combination” of these two parts, enable us to “identify” each of the Array members individually.

PowerShell ForEach statement example - Many to One relationships -03


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

Please rate this

The post Creating a Loop through an array Using the “ForEach” statement and variables | PowerShell environment| Part 2#2 5/5 (2) appeared first on o365info.com.

Save a copy of sent mail items when using Send As permissions | Shared mailbox | Office 365 5/5 (2)

$
0
0

In the current article, we review how to change and manage the default settings of “saving mail items,” in a scenario in which recipient sends E-mail using another recipient “identity” (other recipient E-mail addresses).

By default, when recipient A send E-mail on behalf of recipient B, the sent mail items will be saved in the mailbox of recipient A but will not save in the mailbox of recipient B.

By default, when such a scenario occurs, the mail items that were sent by the recipient who has the Send As permissions (or the Send on Behalf permissions) are saved in the “Sent Item Folder” of the user who sent the E-mail message.

By default, a copy of the sent mail items will not be saved, in the “Sent Item Folder” of the recipient whom the E-mail was sent by his name (by using his identity – E-mail address).

For example, in our scenario user named Bob have send as permissions on Adele’s mailbox.

When Bob sends E-mail to another recipient by using the “identity” of Adele, the sent mail items are saved on Bob’s mailbox “Sent Item Folder.”

Adele is “not aware” to the fact that Bob sends E-mail messages using her name (her E-mail address) because she will not see any copy of the specific E-mail message on her “Sent Item Folder.”

The default policy of saving sent mail items on a scenario of Send As

The good news is that in case that we want to change this default behavior by using the PowerShell command – Set-Mailbox with a specific parameter.

Be define a specific mailbox parameter, we can change the default mailbox setting that relates to the scenario of saving (or not saving) a copy of the mail items that was sent in the “Sent Item Folder” of the recipient whom the E-mail message was sent by using his identity.

The PowerShell commands that we use is “Set-Mailbox” and the specific parameters that we use are:

  1. MessageCopyForSentAsEnabled – this is the PowerShell parameter that we use for defining the “Sent item folder policy,” of the “destination mailbox, in a scenario in which a recipient (the delegate) has, the Send As permissions.
  2. MessageCopyForSendOnBehalfEnabled – this is the PowerShell parameter that we use for defining the “Sent item folder policy,” of the “destination mailbox, in a scenario in which a recipient (the delegate) has, the Send On behalf permissions.

By default, this PowerShell parameter – MessageCopyForSentAsEnabled and MessageCopyForSendOnBehalfEnabled define as “False.”

When we set one of this parameter to “True,” each time that the Mailbox delegate sent mail using the “destination mailbox identity” (using the E-mail address of the mailbox), the sent mail item will be saved in:

  • The “Sent items folder” of the Mailbox Delegate recipient.
  • The “Sent items folder” of the Mailbox.

For example, in our scenario user named Bob have send as permissions on Adele’s mailbox.

When Bon sends E-mail to another recipient by using the “identity” of Adele, the sent mail items are saved on Bob’s mailbox “Sent Item Folder.”

After we set the setting of Adele’s mailbox by setting the PowerShell parameter – MessageCopyForSentAsEnabled as “True,” each time that Bob sends E-mail using Adele’s identity (Adele E-mail address), a copy of the sent mail will also save on Adele’s mailbox in her “Sent Item Folder.”

Change the default policy of saving sent mail items -MessageCopyForSendOnBehalfEnable -02

Standard Exchange mailbox versus Shared mailbox.

The information that was provided in the former section is relevant to any type of Exchange mailbox.

From my experience, the need to change the default setting of “Send mail items” when using the Send As permissions, is most relevant to a scenario in which we use Shared mailbox.

For this reason, all the PowerShell command examples that will be provided will use a “shared mailbox” as the “destination mailbox” but it’s important to emphasize that, you can use the specified PowerShell command to any type of Exchange mailbox.

Set the destination mailbox setting, to save a copy of sent mail items.

Just a quick reminder, when user A send E-mail using the identity of user B, the sent mail will be saved by default only in the Sent mail item folder of the recipient A.

In case that we want that save a copy of the E-mail also in the Sent mail item’s folder of recipient B (destination mailbox), we can use the following settings:

Enable the Save a copy of sending mail items when the user has Send As permissions.

Enable – Save a copy of sending mail items in the Shared mailbox sent items folder

PowerShell command syntax

Set-Mailbox -Identity <identity> -MessageCopyForSentAsEnabled $True

PowerShell command example

Set-Mailbox Bob -MessageCopyForSentAsEnabled $True

Enable – Save a copy of sending mail items in the Shared mailbox sent items folder – All Shared mailboxes (Bulk Mode)

PowerShell command example

Get-Mailbox | Where {$_.RecipientTypeDetails -eq “SharedMailbox”} | Foreach-Object {Set-Mailbox -identity $_.Alias -MessageCopyForSentAsEnabled $True }

Enable the Save a copy of sending mail items when the user has Send On Behalf permissions

Enable – Save a copy of sent mail items in the Shared mailbox sent items folde

PowerShell command syntax

Set-Mailbox -Identity <identity> -MessageCopyForSendOnBehalfEnabled $True

PowerShell command example

Set-Mailbox Bob -MessageCopyForSendOnBehalfEnabled $True

Enable – Save a copy of sent mail items in the Shared mailbox sent items folder – All Shared mailboxes (Bulk Mode)

PowerShell command example

Get-Mailbox | Where {$_.RecipientTypeDetails -eq “SharedMailbox”} | Foreach-Object {Set-Mailbox -identity $_.Alias -MessageCopyForSendOnBehalfEnabled $True }

View mailbox setting that relate to saving a copy of mail items in the sent items folder

View the mailbox setting that relates to saving a copy of sent mail items for a specific Mailbox

PowerShell command syntax

Get-Mailbox -Identity <identity> | FT Alias,MessageCopy*

PowerShell command example

Get-Mailbox Bob | FT Alias,MessageCopy*

View the mailbox setting that relates to saving a copy of sent mail items for ALL Shared Mailboxes (Bulk Mode)

PowerShell command example

Get-Mailbox | Where {$_.RecipientTypeDetails -eq “SharedMailbox”} | FT Alias,MessageCopy*

Display a list of all Shared mailboxes that their RecipientTypeDetails option is “True”

PowerShell command example

Get-Mailbox | Where {$_.RecipientTypeDetails -eq “SharedMailbox” -and $_.MessageCopyForSentAsEnabled -eq $False} | FT Alias,MessageCopy*

Display a list of all Shared mailboxes that their MessageCopyForSendOnBehalfEnabled option is “True”

PowerShell command example

Get-Mailbox | Where {$_.RecipientTypeDetails -eq “SharedMailbox” -and
$_.MessageCopyForSendOnBehalfEnabled -eq $False} | FT Alias,MessageCopy*

Disable the option of - Save a copy of sent mail items in the Shared mailbox sent items folder

Disable the Save a copy of sent mail items when user have Send As permissions

Disable the option of – Save a copy of sent mail items in the Shared mailbox sent items folder

PowerShell command syntax

Set-Mailbox -Identity <identity> -MessageCopyForSentAsEnabled $False

PowerShell command example

Set-Mailbox Bob -MessageCopyForSentAsEnabled $False

Disable the option of – Save a copy of sent mail items in the Shared mailbox sent items folder – All Shared mailboxes (Bulk Mode)

PowerShell command example

Get-Mailbox | Where {$_.RecipientTypeDetails -eq “SharedMailbox”} | Foreach-Object {Set-Mailbox -identity $_.Alias -MessageCopyForSentAsEnabled $False }

Disable the Save a copy of sent mail items when user have Send On Behalf permissions

Disable – Save a copy of sent mail items in the Shared mailbox sent items folder

PowerShell command syntax

Set-Mailbox -Identity <identity> -MessageCopyForSendOnBehalfEnabled $False

PowerShell command example

Set-Mailbox Bob -MessageCopyForSentAsEnabled $False

Disable – Save a copy of sent mail items in the Shared mailbox sent items folder – All Shared mailboxes (Bulk Mode)

PowerShell command example

Get-Mailbox | Where {$_.RecipientTypeDetails -eq “SharedMailbox”} | Foreach-Object {Set-Mailbox -identity $_.Alias - MessageCopyForSendOnBehalfEnabled $False }

Export information about mailbox setting | View information about saving a copy of sent items settings

Export information to a text file

PowerShell command example

Get-Mailbox | Where {$_.RecipientTypeDetails -eq “SharedMailbox”} | FT | Out-File C:\TEMP\"Shared mailbox settings.txt" -Encoding UTF8

Export information to a CSV file

PowerShell command example

Get-Mailbox | Where {$_.RecipientTypeDetails -eq “SharedMailbox”} | Export-CSV C:\TEMP \"Shared mailbox settings.CSV" –NoTypeInformation -Encoding utf8

Export information to a HTML file

PowerShell command example

Get-Mailbox | Where {$_.RecipientTypeDetails -eq “SharedMailbox”} | Select Alias,MessageCopy* | ConvertTo-Html -Body "<H1>Shared mailbox settings </H1>" | Out-File C:\TEMP\"Shared mailbox settings.html"

For your convenience, I have “Wrapped” all the PowerShell commands that were reviewed in the article,
in a “Menu Based” PowerShell Script.

You are welcome to download the PowerShell script and use it.
Download -o365info PowerShell Script

Save a copy of sent items when using Send As permissions | Shared mailbox | Office 365 5/5 (2)


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

Please rate this

The post Save a copy of sent mail items when using Send As permissions | Shared mailbox | Office 365 5/5 (2) appeared first on o365info.com.

Using Get-MessageTrace PowerShell command for viewing and exporting information on mail sent and received | Exchange Online | Part 1#2 5/5 (1)

$
0
0
In the current two-article series, we review the Exchange Online PowerShell command Get-MessageTrace, that is used to view and export information about incoming and outgoing mail transaction that are saved in the Exchange Online Logfiles.

In the first article, we provide a basic introduction to the Get-MessageTrace PowerShell command, and to her “sister” the Get-HistoricalSearch PowerShell command.
Another important concept that we review is the concept of “Date range” that considers as an essential component when using the Get-MessageTrace PowerShell
cmdlet.
In the next article, we provide various types of example to the user of Get-MessageTrace with different parameters and filters such – sender, recipient, subject, IP address and so on.

How to get information stored in Exchange Online log files?

In Exchange Online (Office 365) based environment, every incoming and outgoing mail transaction is “registered” in the Exchange Online log file.

The ways that are available for us, looking at the content of the Exchange Online log file is via the web base interface of Exchange Online admin center or by using PowerShell commands.

When using PowerShell in Exchange Online (Office 365) based environment for query and export information that’s stored in Exchange Online log files, there are two major PowerShell commands that we can use Get-MessageTrace and Get-HistoricalSearch.

Get-MessageTrace Advantages and Disadvantages

Advantages

  • We can use the Get-MessageTrace PowerShell command for view + export information to file “in real time” (in the next section, I will explain the way I use the term “real time”).

Disadvantages

  • The maximum time frame that is available for us when using the Get-MessageTrace PowerShell command is 30 days. In other words, we cannot use the Get-MessageTrace PowerShell command for “fetching” information that is stored in the Exchange Online server log that is age is over 30 days, even though Exchange Online saves mail transaction log information for a period of 90 days.
  • The information that we can display on the PowerShell console or export to a file can be considered as very basic information that doesn’t include a detailed information about the specific mail transaction. Note – we can add the PowerShell command
    Get-MessageTraceDetail for getting additional information, but the information that we can get is still basic versus the information that we get from the PowerShell command – Get-HistoricalSearch

Get-HistoricalSearch Advantages and Disadvantages

Advantages

  • Using the Get-HistoricalSearch, we can get a very detailed information about each mail transaction that was registered in Exchange Online server log files.
  • When using the Get-HistoricalSearch PowerShell command, Exchange Online provides us an extended time frame of 90 days. In other words, we can look for mail transaction information for a period of 90 days (versus the 30-day limitation when using the PowerShell command
    Get-MessageTrace).

Disadvantages

  • When using the PowerShell command Get-HistoricalSearch, the “request for information” is registered as a “task” in Exchange Online, and executed Only after several hours.
  • The information that we get from the PowerShell command Get-HistoricalSearch can be overwhelming (TMI – too much information), and it’s not easy to read and understand the large chunk of information.

Recap

The main advantage of the PowerShell command Get-MessageTrace is its ability to quickly and Effectively help us to get a “high level” information about the mail transaction that registered in the Exchange Online log file.

In case that we need to perform deeper level investigation about a specific mail transaction that was registered in the Exchange Online log file, or gets information about mail transaction older than 30 days, we will need to use the PowerShell command – Get-HistoricalSearch.

Note – At the current time, there is no way for getting the detailed information that appears in the exported file when using the PowerShell command Get-HistoricalSearch by using the Exchange Online web based interface.

You can get more information about how to read the exported information that we get from the PowerShell command Get-HistoricalSearch in the following articlePerforming an Extended Message Trace in Office 365

Working with the Get-MessageTrace PowerShell command | Basic concepts

The MessageTrace PowerShell command serves a “viewer” that we can use for “picking” in the Exchange Online mail transaction log file.

The most fundamental building block is the “time range.”

In case that we don’t use a PowerShell parameter that defines the time range, the
Get-MessageTrace default is to get only the data from the last 48 hours.

The required “time range” is defined by the PowerShell parameters: StartDate + EndDate

After we provide the information about the required time range, we can add additional “blocks” that help us to filter or narrow the search results.

For example,

  • We can ask to get information about mail transactions that related to E-mails, sent from a specific sender or, sent to a specific recipient.
  • We can ask to get information about mail transactions that related to E-mails, with a specific subject or a specific status.

The Get-MessageTrace command building blocks-01

In case that you want to get information about all the available PowerShell parameter when using the PowerShell command – Get-MessageTrace, you can use the Get-Member PowerShell command:

PowerShell command example

Get-MessageTrace | Get-Member

PowerShell console output example

PS C:\script> Get-MessageTrace | Get-Member
TypeName: Deserialized.Microsoft.Exchange.Management.FfoReporting.MessageTrace

Name               MemberType   Definition                                                                                                                                                                  
----               ----------   ----------                                                                                                                                                                  
GetType            Method       type GetType()                                                                                                                                                              
formatProvider)
PSComputerName     NoteProperty string PSComputerName=outlook.office365.com                                                                                                                                 
PSShowComputerName NoteProperty bool PSShowComputerName=False                                                                                                                                               
RunspaceId         NoteProperty guid RunspaceId=9b812ad0-4ca5-404e-85fd-ad4cd78d495d                                                                                                                        
EndDate            Property     System.DateTime {get;set;}                                                                                                                                                  
FromIP             Property     System.String {get;set;}                                                                                                                                                    
Index              Property     System.Int32 {get;set;}                                                                                                                                                     
MessageId          Property     System.String {get;set;}                                                                                                                                                    
MessageTraceId     Property     System.Guid {get;set;}                                                                                                                                                      
Organization       Property     System.String {get;set;}                                                                                                                                                    
Received           Property     System.DateTime {get;set;}                                                                                                                                                  
RecipientAddress   Property     System.String {get;set;}                                                                                                                                                    
SenderAddress      Property     System.String {get;set;}

Define the specific “time\date” range of the information that we want to get from Exchange log files

As mentioned, the most basic building block when using the Get-MessageTrace command is the definition of the required time frame or time range.

The time range is defined by providing the start date and the end date. The time range is the “space” between these two “borders.”

The Get-MessageTrace command - time unites -02

Exchange Online is willing to “expose” the information by using a limitation of maximum 30 days.

Get-MessageTrace the 30 days limit -04

In case that we write a time range that is Greater than 30 days, the following error appears:

Invalid StartDate value. The StartDate can’t be greater than 30 days from today.
+ CategoryInfo : InvalidArgument: (:) [Get-MessageTrace], InvalidExpressionException

When using the Get-MessageTrace command, there are two major syntax methods, that we can use for defining the time range

Option 1 – by “manually writing” the specific dates (the start date and the End date) in the format of month, day and a year (described as <mm/dd/yyyy>).

The Get-MessageTrace command - time unites -03

Option 2 – by using the PowerShell function

The other method which I prefer to use is a method in which we use the PowerShell function – Get-Date.

As the name implies, the Get-Date PowerShell function “fetch” the information about the current time. The information includes the current second, minutes, hour, day, month and a year.

When using the Get-MessageTrace command, the Get-Date PowerShell function is used for defining the “End-Date”.

The “Start-Date” defined by using “time units” such as “AddHours” or “Adddays”, and subtracting this time unit from the current date.

In the following example, we define a time range of “30 days” by using the time unit “Adddays” and using the value “-30”.

This syntax is “telling” PowerShell that we want to define a date that is calculated by subtracting 30 days from the current time (the current time that we get from the Get-Date PowerShell function).

The Get-MessageTrace command - time unites -

Get information about sent\received Emails in a specific time range | Specifying dates using “basic syntax”.

PowerShell command syntax

Get-MessageTrace -StartDate <mm/dd/yyyy> -EndDate <mm/dd/yyyy>

PowerShell command example

Get-MessageTrace -StartDate 01/01/2017 -EndDate 01/30/2017

In the following section, I would like to review a couple of examples if defending time range by using the “other method” in which we use the Get-Date
PowerShell function as a baseline + additional PowerShell time unites the functions such as – AddHours, Adddays etc.

Get information about sent\received Emails in a specific time range | Last X minutes.

Display all Exchange E-mail messages, that were sent and receive in the last 30 minutes.

PowerShell command example

Get-MessageTrace -StartDate (Get-Date).Addminutes(-30) -EndDate (Get-Date)

Get information about sent\received Emails in a specific time range | Last X Hours.

Display all Exchange E-mail messages, that were sent and receive in the last 30 hours.

PowerShell command example

Get-MessageTrace -StartDate (Get-Date).AddHours(-30) -EndDate (Get-Date)

Get information about sent\received Emails in a specific time range | Last X Days.

Display all Exchange E-mail messages, that were sent and receive in the last 30 days.

PowerShell command example

Get-MessageTrace -StartDate (Get-Date).Adddays(-30) -EndDate (Get-Date)

Get information about sent\received Emails in a specific time range | Last X Mounts.

Display all Exchange E-mail messages, that were sent and receive in the last 1 Mount.

PowerShell command example

Get-MessageTrace -StartDate (Get-Date).AddMonths(-1) -EndDate (Get-Date)

Define a time range using variable

In case that you want to avoid from typing long and complex date values, you can use the method, in which the time range will be defined using variables.

The variables that we define, will “contain” the required date range.

The Get-MessageTrace command that we use, define the time range by using the variables that were defined in the “former step.”

PowerShell command example

$DateEnd = Get-Date
$DateStart = $DateEnd.AddHours(-30)

Get-MessageTrace -StartDate $DateStart -EndDate $DateEnd

“Clean” the displayed results from unnecessary information

When we use the MessageTrace PowerShell command in an Exchange Online environment without a very specific filter, the “output” includes unnecessary information (white noise) about “systems” and internal Exchange Online mail messages.

In the following example, we can see information about “system emails”, that is not relevant to our search.

In case that we want to “clean” the search result by removing the information about the “system emails”, we add filters that will instruct PowerShell to “ignore” specific emails such as the system emails.

PowerShell console output example

PS C:\script>  Get-MessageTrace -StartDate (Get-Date).Adddays(-3) -EndDate (Get-Date) 

Received               Sender Address                                                              Recipient Address                                                                Subject                                                                      
--------               --------------                                                              -----------------                                                                -------                                                                      
01/06/2017 5:47:16 AM  Root@o365info2.onmicrosoft.com                                              publicfoldermailboxes.849adb9d4ce04c84bf663a41b011c05e@o365info2.onmicrosoft.com HierarchySync_Ping_4715_a1712e75-0ed6-4a37-a8a1-96d2337c017e                 
01/06/2017 5:37:15 AM  Root@o365info2.onmicrosoft.com                                              publicfoldermailboxes.849adb9d4ce04c84bf663a41b011c05e@o365info2.onmicrosoft.com HierarchySync_IncrementalSync_4714_a1712e75-0ed6-4a37-a8a1-96d2337c017e      
01/06/2017 5:37:15 AM  Root@o365info2.onmicrosoft.com                                              root@o365info2.onmicrosoft.com                                                   HierarchySync_IncrementalSync_4714_a1712e75-0ed6-4a37-a8a1-96d2337c017e      
01/06/2017 5:33:57 AM  wordpress@o365info.com                                                      John@o365info.com                                                                [o365info.com] Please moderate: "Manage Distribution Groups by using Power...
01/06/2017 5:32:19 AM  wordpress@o365info.com                                                      John@o365info.com                                                                [o365info.com] Please moderate: "Manage Distribution Groups by using Power...
01/06/2017 5:27:15 AM  Root@o365info2.onmicrosoft.com                                              publicfoldermailboxes.@o365info2.onmicrosoft.com HierarchySync_Ping_4713_a1712e75-0ed6-4a37-a8a1-96d2337c017e

“Clean” the displayed results from unnecessary information

PowerShell command example

Get-MessageTrace -StartDate (Get-Date).Adddays(-30) -EndDate (Get-Date) |  Where {$_.SenderAddress -notlike '*micro*' -or $_.SenderAddress -notlike '*root*' }

PowerShell console output example

PS C:\script> Get-MessageTrace -StartDate (Get-Date).Adddays(-30) -EndDate (Get-Date) |  Where {$_.SenderAddress -notlike ‘*micro*’ -or $_.SenderAddress -notlike ‘*root*’ }

Received               Sender Address          Recipient Address       Subject                                                                                          Status   
--------               --------------          -----------------       -------                                                                                          ------   
01/06/2017 11:07:36 PM info@twitter.com        info@o365info.com   beauty tips Tweeted: Please RT #beauty #makeup ##skincare MAC Studio Fix Additions               Expanded 
01/06/2017 7:58:22 PM  ilan.caner@gmail.com    John@o365info.com Re:                                                                                              Delivered
01/06/2017 6:00:36 PM  info@hyperfish.com      John@o365info.com       Webinar: Leveraging People Data in SharePoint Intranets Presented by Bonzai Intranet & Hyperfish Delivered
01/06/2017 4:13:15 PM  joanna@getriverteam.com John@o365info.com Easybellezza - 4 things people say about River                                                   Delivered
01/06/2017 4:13:15 PM  joanna@getriverteam.com info@o365info.com   Easybellezza - 4 things people say about River                                                   Expanded 
01/06/2017 12:34:59 PM omsingh.om@outlook.com  john@o365info.com       SEO Service Proposal                                                                             Delivered
01/06/2017 12:33:01 PM seo.devender.raviya@... info@o365info.com       Create an IPhone & Android App for your business                                                 Delivered
01/06/2017 10:13:52 AM noreply-dmarc-suppor... 1u8pjtbx@ag.dmarcian... Report domain: o365info.com Submitter: google.com Report-ID: 9662862343435806656                 Delivered
01/06/2017 10:13:52 AM noreply-dmarc-suppor... dmarc-report@o365inf... Report domain: o365info.com Submitter: google.com Report-ID: 9662862343435806656                 Resolved

For your convenience, I have “Wrapped” all the PowerShell commands that were reviewed in the article,
in a “Menu Based” PowerShell Script.

You are welcome to download the PowerShell script and use it.
Download -o365info PowerShell Script

Using Get-MessageTrace PowerShell command for viewing and exporting information on mail sent and received 5/5 (1)


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

Please rate this

The post Using Get-MessageTrace PowerShell command for viewing and exporting information on mail sent and received | Exchange Online | Part 1#2 5/5 (1) appeared first on o365info.com.

Using Get-MessageTrace PowerShell command for viewing and exporting information on mail sent and received | Exchange Online | Part 2#2 5/5 (3)

$
0
0
The current article is the second article in our two-article series.

In this article, we review how to use the Get-MessageTrace PowerShell command for viewing and exporting information about incoming and outgoing mail transactions that are stored in the Exchange Online log files.

In the former article, we review in details the concept of the “Time ranges” when using the Get-MessageTrace PowerShell command.
In the current article, we continue to explorer the additional parameter that we can use together with the Get-MessageTrace PowerShell command.

The concept of sender and recipient when using the MessageTrace command

Before we start with Get-MessageTrace PowerShell command examples, I would like to quickly relate to the terms – sender and recipient.

In many scenarios, we “filter” or narrow the Get-MessageTrace PowerShell command result by adding filter parameters.

I have notice that the filter parameters described as “sender” and “recipient” sometimes causes confusion, so it’s important to clarify the meaning of these terms.

  • The term “sender,” relate to the originating entity that “write the E-mail message.”
  • The term “recipient,” relate to the “destination entity,” meaning the person or the persons that the E-mail message was sent to them.”

In the following diagram, we can see that when Bob sends E-mail to Adele, Bob defined as the Sender (SenderAddress) and Adele (RecipientAddress) defend as the Recipient.

The Get-MessageTrace command - the sender and the recipient Parameter

Working with the group by PowerShell parameter and Message Trace results

In some scenarios, the information that we want to get about the “mail flow”, is not information about a specific E-mail message\s but instead, a high-level view of the mail transactions that was performed by as specific sender or a specific recipient in a specific time range.

By using the PowerShell command “Group-Object” in addition to the Get-MessageTrace PowerShell command, we can get this “High level view” about emails transactions.

The PowerShell command “Group-Object” help us to “group” information about a specific “property” and in additional, enable us to “count” the number of instances in each group.

Get information about the most “active” organization senders.

In the following example, we want to accomplish the following requirements:

  • We want to get information about each of the emails that was sent from All senders in the last 30 days.
  • We want to present the results grouped by each of the Senders.
  • We want to count the number of E-mail messages that were sent by each Sender.
  • We want to present the results in “descending” way. The purpose of using the “descending” is to easily view, who are the users who send the largest number of mail items.

To get the required information, we use the PowerShell command – Group-Object.
We ask from the command – Group-Object, to perform for us three tasks:

  • Group the results by relating to the property – SenderAddress
  • Count the results for each sender (the number of mail items that a specific sender sent ).
  • Order the information presented in the “count” column in descending order.

The command syntax that we use is:

Group-Object -Property SenderAddress | Select name,count | Sort count -desc

Display information about the number of mail items that was accepted from specific senders

PowerShell command example

Get-MessageTrace -StartDate (Get-Date).Adddays(-30) -EndDate (Get-Date)  | Group-Object -Property SenderAddress | Select name,count | Sort count -desc

PowerShell console output example

S C:\script> Get-MessageTrace -StartDate (Get-Date).Adddays(-30) -EndDate (Get-Date)  | Group-Object -Property SenderAddress | Select name,count | Sort count -desc

Name                                                                        Count
----                                                                        -----
Root@o365info2.onmicrosoft.com                                                889
John@o365info.com                                                              23
apollotheme@gmail.com                                                          14
virus@o365pilot.com                                                             8
info@twitter.com                                                                6
noreply@addthis-email.com                                                       6
noreply-dmarc-support@google.com                                                6
wordpress@o365info.com                                                          5
bob@o365info.com                                                                4
dmarcrep@microsoft.com                                                          4
team@accounts.bitly.com                                                         4
MicrosoftExchange3e@o365info2.onmicrosoft.com                                   2
hemaslab@hemsons-lk.cf                                                          2

Get information about the most “popular” organization recipients.

In the following example, we want to accomplish the following requirements:

  • We want to get information about each of the emails that were received by our user (send to our users) in the last 30 days.
  • We want to present the results grouped by each of the Recipients (RecipientAddress).
  • We want to count the number of E-mail messages that were sent by each Recipients.
  • We want to present the results in “descending” way. The purpose of using the “descending” is to easily view, who are the users who send the largest number of mail items, meaning – the most “active” Recipients (who are the Recipients taht sends that send the largest number of mail items).

To get the required information, we use the PowerShell command – Group-Object.
We ask from the command – Group-Object to perform for us three tasks:

  • Group the results by relating to the property – RecipientAddress
  • Count the results for each recipient (the number of mail items that was sent to the specific recipient).
  • Order the information presented in the “count” column in descending order.

The command syntax that we use is:

Group-Object -Property RecipientAddress | Select name,count | Sort count -desc

Display information about the number of mail items that was received

PowerShell command example

Get-MessageTrace -StartDate (Get-Date).Adddays(-30) -EndDate (Get-Date)  | Group-Object -Property RecipientAddress | Select name,count | Sort count -desc

PowerShell console output example

PS C:\script> Get-MessageTrace -StartDate (Get-Date).Adddays(-30) -EndDate (Get-Date)  | Group-Object -Property RecipientAddress | Select name,count | Sort count -desc

Name                                                                     Count
----                                                                     -----
publicfoldermailboxes.@o365info2.onmicrosoft.com   445
root@o365info2.onmicrosoft.com                                           444
John@o365info.com                                                        30
apollotheme@gmail.com                                                    19
info@o365info.com                                                        14
Jeff@o365info.com                                                        10
dmarc-report@o365info.com                                                5
1u8pjtbx@ag.dmarcian.com                                                 5
Alice@o365info.com                                                                   4
ilan@gmail.com                                                                       3
virus@o365pilot.com                                                                  2
hemaslab@hemsons-lk.cf                                                               2


Get information about emails that was sent from a Specific sender

Using the “SenderAddress” parameter, enable us to get information about emails that were sent by a specific sender\s.

The term “sender” can be translated to – our organization recipients who send E-mails to “other recipients” or external sender who send E-mails to our organization users.

Get information about Emails sent by a specific sender | Basic PowerShell command syntax.

PowerShell command syntax

Get-MessageTrace -SenderAddress <Sender Email address>

PowerShell command example

Get-MessageTrace -SenderAddress Bob@o365info.com

Get information about Emails sent by a specific sender in the last X days.

PowerShell command syntax

Get-MessageTrace -StartDate (Get-Date).Adddays(-x) -EndDate (Get-Date) -SenderAddress <Sender Email address>

PowerShell command example

Get-MessageTrace -StartDate (Get-Date).Adddays(-30) -EndDate (Get-Date) -SenderAddress Bob@o365info.com

Get information about Emails sent by a specific sender in the last X days + count the number of E-mail messages.

In this scenario, we use the PowerShell cmdlet – Group-Object, for counting the number of E-mail messages that were sent by a specific sender.

PowerShell command example

Get-MessageTrace -StartDate (Get-Date).Adddays(-30) -EndDate (Get-Date) -SenderAddress Bob@o365info.com | Group-Object -Property SenderAddress | Select name,count

Get information about Emails sent by a specific sender\s | Sender\s that their E-mail address includes a specific domain name, in the last X days.

PowerShell command syntax

Get-MessageTrace -StartDate (Get-Date).Adddays(-x) -EndDate (Get-Date) -SenderAddress <*@Domain name>

In the following example, we want to get information about all the emails that was sent by “senders,” which their E-mail address includes the domain name – o365info.com in the last 30 days.

PowerShell command example

Get-MessageTrace -StartDate (Get-Date).Adddays(-30) -EndDate (Get-Date) -SenderAddress *@o365info.com

Export information about emails sent from a specific sender to log file | Create a dedicated file for each sender.

In the following section, I would like to demonstrate a more advanced scenario, in which we need to get information about all the mail transaction that was performed by each of the “senders” that appears in the Exchange Online log files.

The information should include all the sender who sent E-mail in the last 30 days.

The requirements that we need to fulfill, include the following parts:

  • The information that we get from the Get-MessageTrace command, will be saved to a CSV (comma separated value) file (exported to CSV file).
  • The special requirement is, that the “export process,” will be implemented by creating a dedicated CSV file, for each of the senders. For example, in case that the sender is – Bob@o365info.com, the dedicated CSV file that will be created for “Bob” will include log information only for emails sent from Bob@o365info.com.

To be able to fulfill this requirement, we will use a PowerShell ForEach statement.

  • In the first phase, we use the ForEach statement, for “looping” via the “array of record” in the Exchange Online log file.
  • In the second phase, we export the required information to a separated CSV file, based on the “sender identity.”

PowerShell command example

$AllSender = Get-MessageTrace -StartDate (Get-Date).Adddays(-30) -EndDate (Get-Date) | Group-Object -Property SenderAddress | Select name
$AllSender = $AllSender.name
$ErrorActionPreference = "SilentlyContinue"
ForEach ($sender in $AllSender)
{
Get-MessageTrace -StartDate (Get-Date).Adddays(-3) -EndDate (Get-Date) - SenderAddress $sender | Export-Csv c:\temp\$sender.csv –NoTypeInformation -Encoding UTF8
}

Note – at the bottom of the article, you can find additional information about the subject
Of -exporting Get-MessageTrace output (information) to various file formats using PowerShell.


Get information about emails that was sent to a Specific recipients

Using the “RecipientAddress” parameter, enable us to get information about emails that were sent to a specific recipient\s.

Most of the time, the term “recipient” is translated to our organization recipients.

Get information about Emails sent to a specific recipient | Basic PowerShell command syntax.

PowerShell command syntax

Get-MessageTrace -RecipientAddress <recipient Email address>

PowerShell command example

Get-MessageTrace -RecipientAddress Bob@o365info.com

Get information about Emails sent to a specific recipient in the last X days.

PowerShell command syntax

Get-MessageTrace -StartDate (Get-Date).Adddays(-x) -EndDate (Get-Date) -RecipientAddress <recipient Email address>

PowerShell command example

Get-MessageTrace -StartDate (Get-Date).Adddays(-30) -EndDate (Get-Date) -RecipientAddress Bob@o365info.com

Get information about Emails sent to a specific recipient in the last X days + count the number of E-mail messages.

In this scenario, we use the PowerShell cmdlet – Group-Object, for counting the number of
E-mail messages that were sent from a specific recipient.

PowerShell command example

Get-MessageTrace -StartDate (Get-Date).Adddays(-30) -EndDate (Get-Date) -RecipientAddress Bob@o365info.com | Group-Object -Property SenderAddress | Select name,count

Get information about Emails sent to a specific recipient\s, that their E-mail address includes a specific domain name, in the last X days.

PowerShell command syntax

Get-MessageTrace -StartDate (Get-Date).Adddays(-x) -EndDate (Get-Date) -RecipientAddress <*@Domain name>

In the following example, we want to get information about all the emails that was sent to a specific recipient\s”, which their E-mail address includes the domain name – o365info.com in the last 30 days.

PowerShell command example

Get-MessageTrace -StartDate (Get-Date).Adddays(-30) -EndDate (Get-Date) -RecipientAddress *@o365info.com


Get information about emails with a specific status

The Status parameter filters the results by the delivery status of the E-mail message. Valid values for this parameter are:

  • None: The message has no delivery status because it was rejected or redirected to a different recipient.
  • Failed: Message delivery was attempted, and it failed or the message was filtered as spam or malware, or by transport rules.
  • Pending: Message delivery is underway or was deferred and is being retried.
  • Delivered: The message was delivered to its destination.
  • Expanded: There was no message delivery because the message was addressed to a distribution group, and the membership of the distribution was expanded.

Get information about sent\received Emails with a specific status | Basic PowerShell command syntax

PowerShell command syntax

Get-MessageTrace -StartDate <mm/dd/yyyy> -EndDate <mm/dd/yyyy> -Status <Status>

Get information about sent\received Emails with a specific status that was sent or received in the last X days

PowerShell command syntax

Get-MessageTrace -StartDate (Get-Date).Adddays(-x) -EndDate (Get-Date) -Status <Status>

In the following example, we want to get information All Emails with a specific status that was sent or received in the last 30 days which their status is – “Failed”.

PowerShell command example

Get-MessageTrace -StartDate (Get-Date).Adddays(-30) -EndDate (Get-Date) -Status Failed

Another optional syntax that we can use for getting information about E-mail message with a specific status is:

PowerShell command example

Get-MessageTrace -StartDate (Get-Date).Adddays(-30) -EndDate (Get-Date) | Where {$_.Status -eq "Failed"}

Export information about Emails with a specific status to File | Create a separated file for each type of status

In the following section, I would like to demonstrate a more advanced scenario, in which we need to get information about the status of all the emails that was Sent and received in the last 30 days.

The requirements that we need to fulfill, include the following parts:

  • The information that we get from the Get-MessageTrace command, will be saved to a CSV (comma separated value) file (exported to CSV file).
  • The special requirement is, that the “export process,” will be implemented by creating a dedicated CSV file, for each of the optional status such as – Failed, None,

To be able to fulfill this requirement, we will use a PowerShell “ForEach” statement.

In the first phase, the ForEach statement, “loop” via the “array of record” in the Exchange Online log file.

In the second phase, we export the required information to a separated CSV file based on the specific mail transaction status.

PowerShell command example

$statuses = "None", "Failed", "Pending", "Delivered", "Expanded"
ForEach ($status in $statuses)
{
Get-MessageTrace -StartDate (Get-Date).Adddays(-30) -EndDate (Get-Date) -Status $status | Export-Csv c:\temp\$status.csv
}

Note – at the bottom of the article, you can find additional information about the subject
Of -exporting Get-MessageTrace output (information) to various file formats using PowerShell.


Get information about emails with a specific subject

The Get-MessageTrace parameter “subject,” enable us to get information about emails that include a specific subject or a specific “string” in the mail subject.

Get information about Emails sent\received with a specific recipient | Basic PowerShell command syntax.

PowerShell command syntax

Get-MessageTrace -StartDate <mm/dd/yyyy> -EndDate <mm/dd/yyyy> | Where {$_.Subject -like "*<string>*"}

PowerShell command example

Get-MessageTrace -StartDate (Get-Date).Adddays(-30) -EndDate (Get-Date) | Where {$_.Subject -like "*test*"}


Get information about emails | Filter information by source or destination IP address

The Get-MessageTrace parameter “ToIP” and “FromIP,” enable us to get information about emails that were sent from a specific IP address or send to a specific IP address.

Most of the times, when using the parameter “ToIP” we relate to the IP address of the mail server which Exchange Online address.

ToIP | Get information about emails that sent to “destination mail server” with a specific IP address.

As mentioned, most of the time the “IP address” is, the public IP address of the mail server that represent specific domain name or specific recipient.

Get information about Emails that was sent to a mail server with a specific IP address.

PowerShell command syntax

Get-MessageTrace -StartDate <mm/dd/yyyy> -EndDate <mm/dd/yyyy> -ToIP <IP address>

In the following example, we see an example of a PowerShell command syntax, that we use for getting information – mail items that was sent in the last 30 days, to a destination mail server, that has the IP address – 10.0.0.2.

PowerShell command example

Get-MessageTrace -StartDate (Get-Date).Adddays(-30) -EndDate (Get-Date) -ToIP 10.0.0.2

The Get-MessageTrace command - TOIP paramter

FromIP | Get information about emails that sent from a specific IP address

The Get-MessageTrace parameter “FromIP,” enable us to get information about emails that were sent from a specific IP address.

Get information about Emails that was revived from a mail server with a specific IP address.

PowerShell command syntax

Get-MessageTrace -StartDate <mm/dd/yyyy> -EndDate <mm/dd/yyyy> -FromIP <IP address>

In the following example, we use a PowerShell command syntax, that will get information about mail items that was sent in the last 30 days, by the mail server that is IP address is – 10.0.0.2.

PowerShell command example

Get-MessageTrace -StartDate (Get-Date).Adddays(-30) -EndDate (Get-Date) -FromIP 10.0.0.2


Define the setting that relates to the maximum number of results

When using the PowerShell command Get-MessageTrace” for displaying information using the PowerShell console, there is a built-in limitation to the number of “log events” (mail transaction” that will be displayed on the PowerShell console screen.

The “unit” which is used for defining the displayed result limitation defined as – “Page.”

By default, each page unit includes 1,000 rows (mail transactions).

By default, the Get-MessageTrace will display an only 1 page.

In other words, in case that the search result includes more than 1,000 results, the Get-MessageTrace command will display a maximum of 1,000 results.

In case that we perform a search that is expected to produce a large number of results, is recommended to define a parameter that will help us to “override”
the built-in defaults of the PowerShell command Get-MessageTrace”.

Get-MessageTrace includes two parameters that relate to the subject of maximum displayed results:

Page The Page parameter specifies the page number of the results you want to view. Valid input for this parameter is an integer between 1 and 1000. The default value is 1.
PageSize The PageSize parameter specifies the maximum number of entries per page. Valid input for this parameter is an integer between 1 and 5000. The default value is 1000.

“Extend” the default page limitation to 5,000 results

PowerShell command syntax

Get-MessageTrace -StartDate <mm/dd/yyyy> -EndDate <mm/dd/yyyy> -PageSize <number or records that each page includes>

PowerShell command example

Get-MessageTrace -StartDate (Get-Date).Adddays(-30) -EndDate (Get-Date) -PageSize 5000


Get more details on a specific mail transaction by using MessageTraceDetail

As mentioned at the begging of the current article, the Get-MessageTrace the command provides us basic information about a specific mail transaction.

In case that we want to get more detailed information about a specific mail transaction, we can use an additional PowerShell command named- MessageTraceDetail

We use the MessageTraceDetail command, as an “addition” to the
original Get-MessageTrace command.

For example:

Get message details for all sent and received emails in the last 30 days

PowerShell command example

Get-MessageTrace -StartDate (Get-Date).Adddays(-3) -EndDate (Get-Date) | Get-MessageTraceDetail


Export information from Get-MessageTrace results to a file

Exporting information to a file using PowerShell is one of the functions that we can implement when using PowerShell “Get” commands.

When using the PowerShell “Get” commands, the “output” (the result from the PowerShell command) can be displayed on the PowerShell console screen or – exported to a file.

Export to file using PowerShell and supported file formats.

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

When we want to export the command output to a File, we need to “tell” PowerShell what is the required file format that we want to use.

In addition to the PowerShell cmdlets that we use to define the specific file format, we can “add” specific parameter that relates to the specific file format.

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 File name and the “path” parameter

A mandatory requirement when export command output to a file is the “File name.”
The additional part is the “Path.” The “path” parameter defines the specific location in which we want to save the file. For example – C:\Temp.

The “path” parameter is not a mandatory parameter. Most of the times, when we export information to a file, we will also provide information. In case that we don’t provide a specific path, PowerShell exports the file to the folder from which we run the PowerShell command.

It’s important to mention that when we provide the name of a specific 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 of file formats.

To export command syntax is built from two parts:

  1. Part 1#2 – this is the part of the “Get PowerShell cmdlets”, that fetch a specific information.
  2. Part 2#2 – this is the part in which we define the specific file format, the path, and the filename.

In the following section, we can see an example of the “export syntax” for three file formats – text, CSV, and HTML.

PowerShell command Example | Export information to Text File

PowerShell command example

Get-MessageTrace -StartDate (Get-Date).Adddays(-30) -EndDate (Get-Date) | Out-File C:\Temp\"All emails in the last month.TXT"

PowerShell command Example | Export information to CSV File

PowerShell command example

Get-MessageTrace -StartDate (Get-Date).Adddays(-30) -EndDate (Get-Date) | Export-CSV C:\Temp\"All emails in the last month.CSV" –NoTypeInformation -Encoding UTF8

PowerShell command Example | Export information to HTML File

PowerShell command example

Get-MessageTrace -StartDate (Get-Date).Adddays(-30) -EndDate (Get-Date) | ConvertTo-Html | Out-File C:\Temp\"All emails in the last month.HTML"

The Get-MessageTrace command - export to file


For your convenience, I have “Wrapped” all the PowerShell commands that were reviewed in the article,
in a “Menu Based” PowerShell Script.

You are welcome to download the PowerShell script and use it.
Download -o365info PowerShell Script

Using Get-MessageTrace PowerShell command for viewing and exporting information on mail sent and received 5/5 (3)


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

Please rate this

The post Using Get-MessageTrace PowerShell command for viewing and exporting information on mail sent and received | Exchange Online | Part 2#2 5/5 (3) appeared first on o365info.com.

Calculating manually the value of the Office 365 DKIM selector host name | Part 6#10 5/5 (1)

$
0
0
In the current article, we review the “formula” that we can use for calculating the value of the two Office 365 DKIM selector TXT record host names who contain the Public Key that the Office 365 DKIM selector use for signing outbound mail.

In the past, to the only way for getting the host name of the Office 365 DKIM selector, was by using the “manual method,” in which we need to “collocate” the DKIM TXT record host name, by using a formula that “construct” the Host name based on “different components” such as – the onMicrosoft domain name, the Office 365 tenant name whom we register and so on.

Later, Office 365 added a new a PowerShell cmdlet named Get-DkimSigningConfig, that was created to simplify this process by, provides us the ability to “display” the Office 365 DKIM selector TXT record host names who were generated for a specific Public domain name.

It’s up to you to choose the “method” (calculate the value versus using PowerShell command) that you prefer.

Note – the article Get the value of the DKIM record for a Domain, using PowerShell | Office 365 | Part 7#10 include a description of how to use PowerShell for generating the Office 365 DKIM selectors host names.

DKIM in Office 365 | using CNAME records that include two host names.

The foundation for the implementation of outbound DKIM signing for a specific domain name in Office 365 environment, is based on the mandatory need to publish two CNAME records that will include information about “our” DKIM infrastructure.

Each CNAME record consisting of two host names.

When a DNS client asks for information about the host name – A, the CNAME record, will redirect the request to Host name – B.

In our scenario, “Host A” is a logical name of a DKIM selector.
We use the term “logical” because, in reality, this DKIM selector host name does not exist.

This “logical” DKIM selector host name,” is added to the outgoing E-mail message, in the process of outgoing DKIM signature.

When the “receiving mail server,” asks the DNS server about “Host – A (the logical name of the DKIM selector),” the DNS CNAME record, will redirect the request to “Host B.”

In our scenario, “Host -B,” is the host name of the “real” Office 365 DKIM selector TXT record, that contains the Public key which was used for signing the outgoing E-mail.

The DKIM CNAME record stature

The structure of the Office 365 DKIM CNAME record is implemented in the following way:

1. The logical DKIM host name (the first part).

The “first part” of the DKIM CNAME record, meaning, the “logical DKIM Selector” host name, is a “fixed value.”

In Office 365, the name of the “logical” DKIM host name is implemented by using the following naming convention:

Selector1._domain key<Public domain name>
Selector2._domain key<Public domain name>

The structure of DKIM DNS record that we use for the logic host name

For example, in our example, we want to implement the option of outbound DKIM signing for the domain name – o365pilot.com

The naming convection - specific domain name example

2. The “real” host name of the Office 365 DKIM selector (the second part).

When we enable the option of DKIM outbound signing, Office 365 generates a dedicated TXT record that contains the public-key value of the Office 365 DKIM selector.

The “host name” of this DKIM TXT record, will be created based on a “formula,” that generate the host name based on the Office 365 tenant and domain names.

In the next section, we will learn how to use this formula for calculating the host name of the Office 365 TXT record that “represent” a specific domain name.

Calculating the Office 365 DKIM TXT record host name

In this section, we review the “formula” that we use for the Office 365 DKIM selector TXT record.

The structure of the “Office 365 DKIM selector TXT record” that is generating for a specific public domain name, is based on the following two “parts”: Domain GUID and onMicrosoft domain name.

The naming convention of the “special” Office 365 DKIM records ?- Two unique elements -01

In case that the thought – “what WT.. Are these terms?”
Do not worry; we will explain them in the next section

DomainGUID and ?onMicrosoft domain name -02

In the following diagram, we can see the structure of the “Office 365 DKIM selector TXT record”.

We can see that the DNS record consisting of four parts:

The different parts of the “special” Office 365 DKIM DNS record -03

In the following diagram, we can see an example of “Office 365 DKIM hostname.”

An example for the special Office 365 DKIM selector host name -04

Part 1 – this is the “reserved host name.”
In Office 365, we will need to define two DKIM records using the following host names: – selector1 and selector2

Part 2 – the second part defines as DomainGUID.
The DomainGUID name is the left part of the Office 365 MX record that represents our registered public domain name.

In the following diagram, we can see an example for MX record that is used in Office 365 for the public domain o365pilot.com

The “left part” of the host name is the Domain GUID

What is the DomainGUID name -05

Part 3 – the DKIM sub domain name

The part of the DKIM subdomain is a “predefined value” that is written using the following naming convention – ._domainkey

The special “dash character that we use for defining the Office 365 hostnames

Notice that the DKIM subdomain vale includes a special dash character that is a mandatory part of the DKIM subdomain value.

Part 4 – the Office 365 tenant name

This is the part that is “taken” from the Office 365 tenant name.

For example – o365info2.onmicrosoft.com

In the following diagram, we can see an example of the Office 365 DKIM selector TXT record host name structure.

Office 365 DKIM record naming convention - The dash character -06

Part 1#2 | How to get the information about our domain GUID in Office 365?

As mentioned, the Domain GUID is the “left part” of the Exchange Online MX record.

To be able to get information about the Office 365 MX records that represent a particular public domain name, we a use a couple of options:

Option 1 – using the Office 365 portal

When we log in to the Office 365 portal, on the left-side menu bar, we can choose the domain menu and then select a specific domain name such as o365pilot.com in our scenario.
To be able to view information about the DNS records that “belong” to the specific domain, we will choose the menu domain settings

How to know what is the Office 365 MX record for a specific registered domain name -07

In the following screenshot, we can see information about the Office 365 MX records of the
domain name – o365pilot.com

The DomainGUID name appears as the left part of the Office 365 MX record.

How to know what is my Office 365 Domain GUID name - Office 365 admin portal -01

Option 2 – using the nslookup tool

Another way that we can use for display information about the MX record of specific Office 365 domains is by using the nslookup command line tool.

We can use the following parameters to query the DNS server regarding the domain name.

Nslookup

Set q=mx

<Domain name>

How to know what is my Office 365 Domain GUID name - Using NSLOOKUP -02

Note – using the option of nslookup is relevant only in a scenario in which the MX for the specific domain point to Office 365 (Exchange Online) infrastructure.

Part 3 – the third part is the DKIM sub-domain (reserved names). As mentioned, this name is the “reserved sub-domain name” (._domainkey).

Part 4 – the fourth part is the “onMicrosoft domain” name.
This is the domain name that automatically generated for our Office 365 tenant in the first time that we create our Office 365 tenant.

What is the onmicrosoft domain name -03

Part 2#2 | How to get the name of the OnMicrosoft domain name?

To be able to get the name of our “onMicrosoft domain” name we can be login to the Office 365 portal.
In the following screenshot, we can see an example to Office 365 tenant that include three registered domain names.

Two of the domain names considers as a “public domain” (other terms, a vanity domain or a custom domain) name and one domain is the onMicrosoft Domain name (number 2).

How to know what is my Office 365 onmicrosoft domain name -04

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

Restore Exchange Online mailbox | Article series index

Please rate this

The post Calculating manually the value of the Office 365 DKIM selector host name | Part 6#10 5/5 (1) appeared first on o365info.com.

Get the value of the DKIM record for a Domain, using PowerShell | Office 365 | Part 7#10 5/5 (2)

$
0
0
The task of getting the value of the DKIM records for a specific domain name in Office 365 based environment, can be described as a “challenging task, ” because, at the current time, there is no “user-friendly” graphic interface that can provide us the information that we need.

The only way for getting the required DKIM host name records is, by implementing a “manual calculation (which was reviewed in a former article) or, by using a PowerShell command that will get us the required DKIM host names.

The additional challenge that stands before of us is, that the PowerShell command that we use, provide only a “partial information” about the Hostnames that we will need to use for creating the required DKIM CNAME records.

To make your life easier, I have written a small PowerShell script , that will “fetch” the required data about the DKIM host names and present the information in a more user-friendly way.

Getting the information about the DKIM CNAME in Office 365

A quick reminder about the implementation of DKIM in Office 365 and the “structure” of CNAME record.

In Office 365 based environment, we need to create two CNAME records, that will be used for outbound DKIM signing for a specific domain name that is hosted at Office 365.

Any CNAME record consists of “two parts”:

  • Part 1#2 – The host name whom the DNS client asks about.
  • Part 2#2 – The “additional host name” to which the DNS client will be redirected.

Generation 1#3

When I wrote the current article series about the – “DKIM infrastructure in Office 365,” the only way that was available for Office 365 customers to get the specific values that need to be configured in the DKIM CNAME records were – by using a long and exhausting process.

The solution was based on a process in which we need to use a “manual formula,” that was supposed to generate the required “values” (hostnames) that we need to use for the two “DKIM CNAME records.”

Note – If you are still interested in the method of – generating the required DKIM CNAME records by using the “Office 365 DKIM formula,” you can read the following article – Calculating manually the value of the Office 365 DKIM selector hostname | Part 6#10

Generation 2#3

Along the way, Microsoft decided to provide PowerShell cmdlets, that will enable us to “get” the required information about – the values that we need to use for the DKIM CNAME records (for our specific domain name).

This is a better solution versus the “manual calculation” of the “Office 365 DKIM formula” but the “PowerShell solution” is not perfect because the process sufferers from major drawback – the PowerShell output that we get, is related only to the “second part” of DKIM CNAME record.

In other words, the PowerShell output provides us only “half of the required information” that is needed for the purpose of – creating two CNAME records.

I believe that most of us would expect to get a more “clear” output that just says something
like: “dear sear \ lady, the DKIM CNAME records that you need to create will need to include the following values: X, Y, Z””

For this reason, I write a little PowerShell script that supposed to simplify the task of “fetching” the required information about the – content of the DKIM CNAME records per.

Generation 3#3

I believe that in the future, the “Office 365 guys,” will provide some “graphic interface,” that will help us to understand beater the exact syntax that we need to use for our DKIM CNAME records pair.


Option 1#2 - Getting the host name of Office 365 DKIM selector using PowerShell

To get the information about the Office 365 selectors host names for a specific domain name, we use the PowerShell command – Get-DkimSigningConfig.

It is important to emphasize that this PowerShell command will provide the information only about the “second part” of the CNAME record that we will need to create.

The PowerShell cmdlet - Get-DkimSigningConfig provide us only Half of the information

The PowerShell syntax that we need to use is as follows:

PowerShell command syntax

Get-DkimSigningConfig <domain name> | FL *CNAME

For example, in our scenario, we wish to get the information about the Office 365 DKIM selectors record that represents the domain name – o365pilot.com, we use the following syntax:

Get-DkimSigningConfig o365pilot.com | FL *CNAME

PowerShell console output example

Get-DkimSigningConfig o365pilot.com | FL *CNAME

Selector1CNAME : selector1-o365pilot-com._domainkey.o365info2.onmicrosoft.com
Selector2CNAME : selector2-o365pilot-com._domainkey.o365info2.onmicrosoft.com

In the following screenshot, we can see the result of the PowerShell
command Get-DkimSigningConfig
Get information about DKIM CNAME record – Office 365 Get-DkimSigningConfig -01

In our specific example, the “second part” of the two DKIM CNAME records that we need to create will redirect DKIM DNS queries to the following host names:

selector1-o365pilot-com._domainkey.o365info2.onmicrosoft.com
selector2-o365pilot-com._domainkey.o365info2.onmicrosoft.com

The “first part” of the Office 365 DKIM record

Notice that the “complete” syntax for the DKIM CNAME record includes two parts.

As mentioned, the PowerShell command Get-DkimSigningConfig, provide us only the “second part” of the DKIM CNAME record.

The “first part” of the Office 365 DKIM record is a “fixed value,” that we use for all the public domain and its used by every Office 365 tenants.

For example, in a scenario in which we need to define the “first part” of the CNAME records, for the domain name – o365pilot.com, the syntax will be implemented as follows:

First CNAME record The “first part” of the “first Office 365 DKIM CNAME record” is always – Selector1._domainkey.

The FQDN (Fully Qualified Domain Name) of the host in our example will be:

Selector1._domainkey.o365pilot.com

Second CNAME record The “first part” of the “second Office 365 DKIM CNAME record” is always –Selector2._domainkey.

The FQDN (Fully Qualified Domain Name) of the host in our example will be:

Selector2._domainkey.o365pilot.com

The two parts of Office 365 DKIM CNAME records


Option 2#2 - How to use the – “Show my Office 365 CNAME DKIM records” PowerShell script

To make this task more user-friendly, I have created a simple menu based PowerShell script, that will “fetch” the information about the required syntax for an Office 365 DKIM CNAME record (for a specific domain name), and display the information in a convenient way to understand.

Running the Show my Office 365 CNAME DKIM records” PowerShell script

We will run the menu based PowerShell script – “Show me CNAME DKIM records,” by using standard PowerShell console.

First-time configurations

In case that this is the first time that you run a PowerShell script, you will need to “allow” PowerShell console to run a PowerShell script.

  1. Right click on the PowerShell console icon, and select the menu “Run as Administrator
  2. Copy and paste the following command – Set-ExecutionPolicy Unrestricted –force
  3. From the PowerShell console, you will need to “call” the dkim.ps1 PowerShell script.

Step 1#2 – login to Exchange Online using remote PowerShell session

To initialize the remote PowerShell session to Exchange Online, select the menu option “1
( 1) Login to Exchange Online using Remote PowerShell)

Export information about Office 365 CNAME DKIM records using a PowerShell script -01

Provide your Office 365 Global Administrator credentials

Get information about DKIM CNAME record – Office 365 Get-DkimSigningConfig -02

Step 2#2 – display and export information about Office 365 DKIM CNAME records for a specific domain name.

Select menu option number “2” (the menu named – 2)
(2) View and export information on the DKIM host name record for a specific Domain name)

Get information about DKIM CNAME record – Office 365 Get-DkimSigningConfig -03

You will need to provide the specific domain name.

This is the “domain name,” for which we need to get the information about the Office 365 DKIM CNAME record hosts names.

In our example, the domain name is – o365pilot.com

Get information about DKIM CNAME record – Office 365 Get-DkimSigningConfig -04

The information about the Office 365 DKIM CNAME record hosts names is:

  1. Displayed on the PowerShell console.
  2. Exported to files to a new folder named- INFO\DKIM Record Settings that will be created on Drive C:

In the following screenshot, we can see the result.

The information displayed on the PowerShell console, describe the host names whom we need to define for the two DKIM CNAME records.

Get information about DKIM CNAME record – Office 365 Get-DkimSigningConfig -05

In the following screenshot, we can see the new INFO folder that was created.

The files are stored in the folder named – DKIM Record settings.

Export information about Office 365 CNAME DKIM records using a PowerShell script -06

We can see that the information is stored in a TEXT file + HTML file.

Using an HTML file enables us to understand better the specific host name that we need to create because the information includes a screenshot.

Export information about Office 365 CNAME DKIM records using a PowerShell script -07

In the following screenshot, we can see the structure of the HTML file.
The HTML file includes the required information for the two DKIM CNAME records that we will need to create.

Export information about Office 365 CNAME DKIM records using a PowerShell script -08

In the following screenshot, we can see the result for the domain name that we provide (o365pilot.com in our example).

Part A – this is the “first part” of the DKIM CNAME record that we need to publish.

In our specific example, the first part of the DKIM CNAME record is the host name – Selector1._domainkey.

Part B – this is the “second part” of the DKIM CNAME record that we need to publish.

In our specific example, the second part of the DKIM CNAME record is the host name –

selector1-o365pilot-com._domainkey.o365info2.onmicrosoft.com.

Part C – this is just a “sample” screenshot, that demonstrates the structure of a “standard CNAME record”, and the “locations” which we need to use for “entering” the specific host names.

Export information about Office 365 CNAME DKIM records using a PowerShell script -09

The DKIM menu based PowerShell script.

The DKIM menu based PowerShell script, include additional options.

For example, by using the menu option “3” (the menu named – 3) (3) View and export information about the DKIM host name record for ALL Domain names), we can view and export information about the Office 365 DKIM CNAME record, for all the existing domain names, including the onMicrosoft domain names.

Export information about Office 365 CNAME DKIM records using a PowerShell script -10-

In the following screenshot, we can see the results.

Export information about Office 365 CNAME DKIM records using a PowerShell script -11

The next step

The next step is creating the required DNS CNAME records.

In the next article, you can find a step by step guide that will walk you through the process.

Download the “Show me my DKIM host name record” PowerShell script

For your convenience, I have “Wrapped” all the PowerShell commands that were reviewed in the article,
in a “Menu Based” PowerShell Script.

You are welcome to download the PowerShell script and use it.
Download -o365info PowerShell Script

DKIM Powershell Script 5/5 (2)
In case you want to get more detailed information about how to use the o365info menu PowerShell script, you can read the following article

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

Restore Exchange Online mailbox | Article series index

Please rate this

The post Get the value of the DKIM record for a Domain, using PowerShell | Office 365 | Part 7#10 5/5 (2) appeared first on o365info.com.


How to create the CNAME records for Outbound DKIM signing using GoDaddy DNS | Office 365 | Part 8#10 5/5 (1)

$
0
0

In the current article, we provide step by step guideline, for the task of – creating the required two “DKIM CNAME records,” that we needed to publish.

This is a preliminary step that we must complete. Only after the required “DKIM CNAME” records were successfully created, we can continue to the last step, in which we enable that outbound DKIM signing for a specific domain name registered with Office 365.

Scenario and task description

The scenario

The domain for which we want to activate the “outbound DKIM signing” is – o365pilot.com

The prerequisite for enabling the outbound DKIM signing is – a creation of two CNAME records, that will be created in the DNS server who hosts the specified domain.

In our scenario, the 2 “DKIM CNAME” records, will include the following host’s names:

CNAME record 1#2
  • Host = selector1._domainkey
  • Points to => selector1-o365pilot-com._domainkey.o365info2.onmicrosoft.com
CNAME record 2#2
  • Host = selector2._domainkey
  • Points to => selector2-o365pilot-com._domainkey.o365info2.onmicrosoft.com
Note – in case that you need to get more information about this specific host’s names whom we use in our scenario, and the PowerShell command that we use for getting the required host names for a specific domain; you can read the article – Get the value of the DKIM record for a Domain, using PowerShell | Office 365 | Part 7#10.
.

The Task

Using our public DNS management interface for creating the required two CNAME record that will be used for DKIM outbound signing in Office 365 environment.

Creating the required two CNAME required for Outbound DKIM signing using GoDaddy DNS management interface.

In the next section, I will demonstrate how to create the two CNAME records, that will point to the Office 365 DKIM Selectors using the GoDaddy DNS management interface.

Regarding “other DNS management interfaces,” the major concepts of creating CNAME records are less or more the same on every DNS management interface, beside of some minor changes.

Creating DKIM CNAME records for Outbound DKIM signing – Office 365 - 01

In the Gooday DNS management interface

  • Select the DNS ZONE FILE tab
  • Select the option of – Add Record

Creating DKIM CNAME records for Outbound DKIM signing – Office 365 - 02

In our scenario, we would like to create a NEW CNAME record.

  • In the RECORD TYPE:* option box, click on the small arrow

Creating DKIM CNAME records for Outbound DKIM signing – Office 365 - 03

  • Select the option of – CNAME (Alias) record

Creating DKIM CNAME records for Outbound DKIM signing – Office 365 - 04

In our specific scenario, the CNAME record will include the following hosts names:

In the “upper section” named – HOST:, we will add the host name: selector1._domainkey

It’s important to understand that because this hostname is hosted “under” the domain name –  o365pilot.com , the FQDN (Fully qualified Hostname) will be – selector1._domainkey.o365pilot.com

In other words, don’t add the “full hostname” in the upper part, but only the “partial hostname” without the “Domain suffix part.”

The host name in the “upper part,” will be used for redirected requests to the dedicated Office 365 DKIM Selector record, that includes the Office 365 DKIM Public Key.

In the “bottom section” named – POINTS TO:, we will add the following host name:

selector1-o365pilot-com._domainkey.o365info2.onmicrosoft.com

Creating DKIM CNAME records for Outbound DKIM signing – Office 365 - 05

Before we continue, it’s important to me to briefly review the concept of the DNS CNAME record because, many times this concept can be a bit confusing.

The CNAME record serves as a “logical router” that accepts a request for “object A” and redirects the required to “object B.”
In our case, each DNS query for the “DKIM selector” that is represented by the host name – selector1._domainkey.o365pilot.com, will be redirected
to the Host name selector1-o365pilot-com._domainkey.o365info2.onmicrosoft.com

The flow logic of CNAME record When asking for Host X-the request will be redirected to host Y

Creating and configuring the second DKIM CNAME record

We will need to repeat this process for cratering an additional CNAME record, that will use for redirecting DKIM request to additional Office 365 host named – selector2

To add an additional record, we will click on the button – ADD ANOTHER

In the “upper section” named – HOST:, we will add the host name: selector2._domainkey

In the “bottom section” named – POINTS TO:, we will add the host name:

selector2-o365pilot-com._domainkey.o365info2.onmicrosoft.com

Creating DKIM CNAME records for Outbound DKIM signing – Office 365 - 07

  • Save the new CNAME records that added by selecting the menu – Save Changes.

Creating DKIM CNAME records for Outbound DKIM signing – Office 365 - 08

In the following screenshot, we can see the result; two new CNAME records created.

Creating DKIM CNAME records for Outbound DKIM signing – Office 365 - 09

The next step

It’s recommended to continue to read the next article, which describe the “next step,” in which we review the process of – verify if the DKIM CNAME records are successfully published and available for external clients.

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

Restore Exchange Online mailbox | Article series index

Please rate this

The post How to create the CNAME records for Outbound DKIM signing using GoDaddy DNS | Office 365 | Part 8#10 5/5 (1) appeared first on o365info.com.

Verifying that the DKIM CNAME records configured properly | Office 365 | Part 9#10 5/5 (2)

$
0
0

In the current article, we review to process of – how to verify the DNS CNAME DKIM records, that represent a domain hosted at Office 365.
The process of verifying the Office 365 DKIM CNAME records include three parts:

  1. Verify that the two CNAME records were successfully published.
  2. Verify that the CNAME “redirect” process is successfully implemented.
  3. Verify that we manage to access the Office 365 DKIM selector TXT record, that includes the Public Key of the Office 365 selectors.

A little about the concept of DKIM records in Office 365 environment

A quick reminder about the concept of DKIM host records in Office 365:

When we implement outbound DKIM signature in an Office 365 environment, outbound E-mail that sent to external recipients, will include DKIM signature + the “logical host name” of the DKIM selector that sign the E-mail.

in our example, the logical host name that represent the domain o365pilot.com is – selector1._domainkey.o365pilot.com.

We use the term “logical host name” because, the DKIM selector host name which appears on the E-mail message doesn’t exist!

When the “destination mail server” receives the E-mail message, he addresses a public DNS server, looking for information about the DKIM selector host name, that appeared in the mail header (“logical host name”).

The external mail server asks the DNS server if he has a TXT record, that uses the specific host name.

The DNS server include a CNAME record, that serves as a “logical router” that “route” DNS client request to “another host”.

redirect DNS queries to the Office 365 selector Host name

The DNS server “answer” is, a redirection to “another host.” In our example, the redirection message includes the host name –
selector1-o365pilot-com._domainkey.o365info2.onmicrosoft.com

The “other host name” is the real host name of the Office 365 DKIM selector.

DKIM and DNS infrastructure – Office 365 scenario -01

The “mail server” addresses again the DNS server, and asks the DNS server if he has a TXT record that uses the specific host name.

In this step, the DNS sends to the “DNS client” (the mail server) the content of the TXT record, that includes the Public Key of the Office 365 selector that signed the E-mail message.

DKIM and DNS infrastructure – Office 365 scenario -02

Scenario and task description

The scenario

The domain name for which we have already activated the “outbound DKIM signing” is – o365pilot.com.

The prerequisite for enabling the outbound DKIM signing in Office 365 is – a creation of two CNAME records, that will be created on the DNS server, who hosts the specified domain.

Note – we review the process of creating the required two CNAME records in the former article.

In our scenario, the 2 “DKIM CNAME” records, will include the following host’s names:

CNAME record 1#2

  • Host = selector1._domainkey
  • Points to => selector1-o365pilot-com._domainkey.o365info2.onmicrosoft.com

CNAME record 2#2

  • Host = selector2._domainkey
  • Points to => selector2-o365pilot-com._domainkey.o365info2.onmicrosoft.com

Note – in case that you need to get more information about this specific host’s names whom we use in our scenario, and the PowerShell command that we use for getting the required host names for a specific domain; you can read the following article.

The Task

Our task is to verify that when the external mail server gets E-mail send from our organization recipient; he will manage to complete the DKIM verification process.

  • We need to verify that “External mail server,” can address public DNS server, which contains information about our domain name (com in our scenario). The external mail server will send a DNS query, looking for information about the “logical name” of the DKIM selector that appears in the outbound E-mail.
  • Verify that the external mail server DNS query, will successfully be redirected to the “real” Host name of the Office 365 DKIM selector.
  • Verify that the external mail server successfully gets the value of the Public key that is stored within the TXT record.

Verifying the information from the DKIM CNAME records in an Office 365 environment

Step 1#2 | How to verify that the two DKIM CNAME records were successfully published + the CNAME “redirect” process is successfully implemented?

In our scenario, the “logical” host name – “selector1._domainkey.o365pilot.com , should redirect DNS queries to the Office 365 DKIM selector
“real” host name- selector1-o365pilot-com._domainkey.o365info2.onmicrosoft.com.

To verify this “Flow” we will simulate a DNS query.

Technically speaking, there are many methods and free web-based tools, that enable us to verify information about DNS records such as a CNAME record.

In our example, I will use the MXTOOLBOX site, for verifying information about the DKIM CNAME record that we publish.

To perform a CNAME look, we will use the following link – MXTOOLBOX CNAME record lookup

To verify that our CNAME record was successfully published, and in addition, perform the required “redirection,” we will need to provide the “first part” of the CNAME record.

In our specific scenario, the host name is – “selector1._domainkey.o365pilot.com.

How to verify that the two DKIM CNAME records was successfully published -01

In the following screenshot, we can see that the test complete successfully.

In the result’s pen, we can see that the “CNAME redirection” process, was successfully completed.

The query for the specific host name whom we provide in the former step, was “redirected” to the Host name – selector1-o365pilot-com._domainkey.o365info2.onmicrosoft.com.

How to verify that the two DKIM CNAME records was successfully published -02

Step 2#2 | How to verify the “content” of the Office 365 DKIM text record that represents our public domain name.

In this step, we want to verify if the Office 365 DKIM text record, that represents our public domain name, includes the required information – the DKIM Public key value.

To be able to perform this test, we need to know the Host name of the “real Office 365 DKIM selector” host name.

In this scenario, we query the public DNS about the content of a “TXT DNS record.”

To perform a query about a TEXT record, use the following link – MXTOOLBOX TXT record lookup

In our scenario, we look at a TXT record that uses the following host name:

selector1-o365pilot-com._domainkey.o365info2.onmicrosoft.com

How to verify the conten” of the Office 365 DKIM TXT record that represent our public domain name -01

In the following screenshot, we can see the results.

The results include the information that is “stored” in the TXT record.
In our case, the Office 365 TXT record stores the Public key of the Office 365 DKIM selector, that represent our domain name.

How to verify the conten” of the Office 365 DKIM TXT record that represent our public domain name -02

Additional methods for verifying DKIM DNS records

In this section, I would like to review more “sophisticated” test options, that are offered by the MXTOOLBOX site.

Versus the “tests” that we review in the former section, MXTOOLBOX includes a “dedicated tool” that we can use for testing a DNS record that was created for publishing DKIM infrastructure.

When using the DKIM records lookup, we will need to provide:

  1. The domain name that uses DKIM services, in our example – com
  2. The host name of our DKIM selector in our example – selector1

Notice that the DKIM record lookup tool is “Smart enough” to complete by himself all the rest of the information.

For example, the DKIM record lookup tool “know” that the FQDN of DKIM host record includes additional “parts” such as the “reserved name” – ._domainkey” and the domain name suffix that needs to be added to the host name.

Verifying DKIM record syntax and content -01

In the following screenshot, we can see the result

We can see that the DKIM record lookup tool manages to “locate” the DNS record of the DKIM selector that “represent” the o365pilot.com domain.

In additional, the “CNAME redirection” process was successfully completed and in the “result page,” we can see the content of the Office 365 TXT record that included the value of the public DKIM key.

Verifying DKIM record syntax and content -02

Additional reading

Attached link to additional web-based tools that you can use for validating the DKIM DNS records that represent your domain name:

It is important for us to know your opinion on this article

Restore Exchange Online mailbox | Article series index

Please rate this

The post Verifying that the DKIM CNAME records configured properly | Office 365 | Part 9#10 5/5 (2) appeared first on o365info.com.

Enabling Outbound DKIM signing + Verifying the process of Outbound DKIM signing in the Office 365 environment | Part 10#10 5/5 (2)

$
0
0

In the current article, we were complete to process of “Enabling Outbound DKIM signing” in an Office 365 based environment.In addition, we review how to verify that the process of outgoing DKIM signature is implemented properly.

Activating (enabling) the Outbound DKIM signing for our domain name

In this phase, we assume that the required DNS CNAME records that redirect “DKIM queries” to the “dedicated Office 365 DKIM selector host name” that represent our public domain name were already created.

Note – we have reviewed the process of creating it requires DKIM CNAME records in the former article.

To activate (enabling) the option of Outbound DKIM signing for a specific domain name, use the following steps:

In our example, we want to enable Outbound DKIM signing for the domain – o365pilot.com.

In the following screenshot, we can see that by default, the option of – Outbound DKIM signing option for the public domain name, is disabled. In other words, the option of “Enable” is active.

Activating the option of Outbound DKIM signing in Office 365 -01

To enable Outbound DKIM signing for the domain – o365pilot.com, all we need to do is – to select the required domain name, and click the Enable menu.

Activating the option of Outbound DKIM signing in Office 365 -02

In the following screenshot, we can see that the Outbound DKIM signing is Enabled

Activating the option of Outbound DKIM signing in Office 365 -03

An additional option for enabling Outbound DKIM signing for a domain is via the – Office 365 Security & Compliance portal

Activating the option of Outbound DKIM signing in Office 365 -04

Verifying the process of Outbound DKIM signing + incoming DKIM verification test

After we have enabled the option of Outbound DKIM signing, the next task is to verify that the configuration is implemented properly.

Our expectations are, that E-mail that is sent by our organization recipients, whom their E-mail address includes the domain name suffix for which we enabled the Outbound DKIM signing, will be signed by a DKIM selector, that his host name include our domain name.

For example, each E-mail that sent from the domain o365pilot.com, will contain information about a DKIM selector, that his host name includes the domain name o365pilot.com.

Scenario A – testing the Outbound DKIM signing ?for an o365pilot.com recipient -01

Just a quick reminder, in an Office 365 based environment, each “outgoing E-mail” will be automatically included DKIM signature, using the “default Office 365 DKIM selector” that use the domain name – “onMicrosoft”.

The purpose of enabling Outbound DKIM signing is – to change this default, so the DKIM selector name will include our domain name suffix.

After we enable the option of – Outbound DKIM signing, the “DKIM signature” will not include the default Office 365 DKIM selector host name (onMicrosoft) and instead, in our example, will include the host name selector1._domainkey.o365pilot.com or, the host name – selector2._domainkey.o365pilot.com.

If we want to be more accurate, although the “formal” host name of the DKIM selector that represents our domain name is “selector1._domainkey.o365pilot.com”, the “destination mail server”, will relate to a shorten version of the host name.

When we look at the information that appears in the E-mail message header that was sent to external recipient, the DKIM selector host name will appear as “Selector1.o365pilot.com”.

Note – If you need to read more information about the process in which we get the information about the “dedicated host name” which Office 365 “generate” for our public domain, you can read the following article – Get the value of the DKIM record for a Domain, using PowerShell | Office 365 | Part 7#10

In the next sections, we review the process in which we verify that the Office 365 DKIM infrastructure functioning properly.

In the next section, we will run two “DKIM outgoing flow” test.

The verification process of the Outbound DKIM signing will be implemented by:

  • Test 1 – Analyzing the E-mail message header that was sent to the “destination recipient”, using the Microsoft Remote Connectivity Analyzer.
  • Test 2 – Analyzing the E-mail message header that was sent to the “destination recipient”, using a free web-based tool.

Verifying the process of Outbound DKIM signing – Analyzing E-mail header
| Using Microsoft Remote Connectivity Analyzer

In this section, we want to verify that the Office 365 DKIM infrastructure is “working properly,” and
that E-mail messages that sent by our organization recipients are

  • Digitally signed by using a DKIM signature
  • That the DKIM selector that sign the E-mail is using the host name o365pilot.com

Scenario description

Our organization mail infrastructure (Exchange Online), was configured to implement Outbound DKIM signing for the public domain name – o365pilot.com.

In our scenario, an organization recipient who uses the E-mail address – craig@o365pilot.com, sent E-mail to external recipients.

Analyzing the information stored in the E-mail header | Destination recipient

In the following screenshot, we can see the E-mail message that was sent to “G-Mail recipient.”

Verifying the process of Outbound DKIM signing send E-mail to external recipient -01

  • To view to E-mail header, we select the E-mail message.
  • Click on the small arrow that appears on the right side.
  • Select the menu – Show original.

Verifying the process of Outbound DKIM signing send E-mail to external recipient -02

In the following screenshot, we can see that the DKIM signature was “approved” by the mail server that accepts the E-mail.

The information about the DKIM signature appears as – “PASS with domain o365pilot.com”.

To get more detailed information, we will copy the content of the E-mail header and analyze the information by using mail header analyzer.
Verifying the process of Outbound DKIM signing send E-mail to external recipient -03

In the next step, we will use the Microsoft E-mail header analyzer using a web-based tool
named – Microsoft Remote Connectivity Analyzer

  • Paste the content of the E-mail header in the “white box”
  • Select – Analyze headers

Verifying the process of Outbound DKIM signing send E-mail to external recipient -04

In the following screenshot, we can see the information about the “DKIM signature.”
The information includes the Public Key that the DKIM selector use.

The important information in our case is, the name of the DKIM selector that “stamp” the E-mail using a DKIM signature.

Verifying the process of Outbound DKIM signing send E-mail to external recipient -05

Authentication-Results

In the section named – “Authentication-Results”, we can see that the DKIM test was successful

The information appears as – “dkim=pass header.i=@o365pilot.com”.

Verifying the process of Outbound DKIM signing send E-mail to external recipient -06

DKIM-Signature

In the section named – “DKIM-Signature,” we can see the information about the “DKIM Selector” host name.

In our example, the DKIM selector host name is – d=o365pilot.com; s=selector1;

  • The letter “d” represent the Domain name (o365pilot.com in our example).
  • The letter “s” represent the selector host name (selector1 in our example).

Verifying the process of Outbound DKIM signing send E-mail to external recipient -07

Verifying the process of Outbound DKIM signing – Analyzing E-mail header | Using web-based tools

In the next step, we perform the “Outbound DKIM signing test” using a free web-based tool
named – DKIM, SPF, SpamAssassin Email Validator

The verification process is implemented by sending E-mail to a “unique E-mail address” that provided by the web-based tool.

The E-mail message that we send will be accepted by the “destination mail server”, and after the E-mail is accepted, the web-based tool will provide a report that relates to the result of the DKIM signature test.

  • Copy the E-mail address that appears on the web page.

Validate your DKIM outbound signing process -001

In this step, we send E-mail to the specific E-mail address from one of our organization users.

In our example, we want to verify the E-mail message that sent from a recipient who uses the domain name suffix – o365pilot.com include a “proper” DKIM signature.

Validate your DKIM outbound signing process -002

After the E-mail message was sent, we will access the Web-based tool again and select the button – View Results

Validate your DKIM outbound signing process -003

In the following screenshot, we can see the content of the E-mail message that was accepted by the “destination recipient.”

Validate your DKIM outbound signing process -004

The information about that the “DKIM signature” inform us that the DKIM test “pass”, and the important thing is that the DKIM selector host name who signed the E-mail message is – selector1.o365pilot.com.

Validate your DKIM outbound signing process -005

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

Restore Exchange Online mailbox | Article series index

Please rate this

The post Enabling Outbound DKIM signing + Verifying the process of Outbound DKIM signing in the Office 365 environment | Part 10#10 5/5 (2) appeared first on o365info.com.

Mailbox migration to Office 365 the PowerShell migration entities | Part 1#5 5/5 (2)

$
0
0

The current article is the first article in a series of five articles, that deal with the subject of using PowerShell as a tool for getting information about the mailbox migration process from the On-Premise environment to Office 365 (Exchange Online).In the first article, we review the following subjects:

  • The various entities that are involved on the mailbox migration process.
  • The relationship between these entities.
  • The PowerShell commands that we use for address each of this “migration entity”.

The content of the article series

In the second article, we review the various PowerShell commands that we can use for getting, and exporting information about the mailbox migration process such as – Get-MoveRequest, Get-MoveRequestStatistics, Get-MigrationUser, Get-MigrationUserStatistics and more.

In the third article, we review how to use a menu based PowerShell script that I have written that will simplify the process of:

  • Connecting to Exchange Online using remote PowerShell.
  • Exporting information about the migration process to various file types.
  • Export information from on-Premises environment that include On-Premise Active Directory and Exchange on-Premises.
  • Perform basic troubleshooting steps in Exchange on-Premises environment.

Exchange on-Premises versus Exchange Online

Although the focus in the current article series is – the migration process that is implemented by migrating Exchange on-Premises mailboxes to Office 365, most of the concepts and the PowerShell commands that we review, are also relevant to Exchange on-Premises based environment.

The terms that we use for defining a mailbox migration process

Mailbox move

In Exchange based environment, the term “mailbox migration” is translated into the term “Mailbox move”.

As the name implies, when we “migrate” Exchange mailbox from Exchange Database A to Database B, or from Exchange server A to Exchange server B (from Exchange on-Premises infrastructure to Exchange Online infrastructure in our scenario), Exchange server relate to the migration process as a “Mailbox move”.

Move request

The process of mailbox migration is realized is “Move request

The Exchange server that is going to be the “NEW host” of the mailbox (the “receiving Exchange server”), send a “Move request” to the Exchange server the is currently host the mailbox.

In our specific scenario, Exchange Online server “requests” from Exchange on-Premises to Move a specific mailbox.

The relationship of Exchange mailbox and Active Directory user account

Although we use most of the time the term “Mailbox”, it is important to emphasize that Exchange mailbox is not a “standalone entity”.

Instead, each Exchange mailbox is associated with Active Directory user (mailbox owner).
So, if we want to be more accurate, when we use the term “mailbox migration” we are also relating to the “user account entity” that is associated with the Exchange mailbox.

The mailbox migration process relates to the user account that is associated with the Exchange mailbox as – “Migrated user”.

This term “Migrated user” can be a little bit confusing because, in reality, we don’t relay migrate the Active Directory user account.

In Office 365 infrastructure, we assume that that the mailbox migration process will “copy” the On-Premise Active Directory user account to the cloud or ,another option is, using Directory synchronization server that synchronized the On-Premise Active Directory user account to the cloud (Azure Active Directory).

The term Mailbox Migration

The mailbox migration entities

The “Mailbox migration process” is composed from couple of “entities”.

Before we start to run the related PowerShell commands, it’s important that we get a general concept of the various “entities” that involved in this process (the mailbox migration to Office 365) and the “role” of each of these entities.

In the following diagram, we can see an example of the “entities” that are involved in the process.

The entities that involved in the mailbox migration to Office 365 and the associated PowerShell commands -02

The “entities” that involved in the mailbox migration to Office 365 and the associated PowerShell commands

Exchange PowerShell cmdlets that relate to the process of mailbox migration, enable us to address each of this “entities” that involved in the mailbox migration process.

The purpose of this “Get” PowerShell cmdlets is – getting information about the various migration entities such as – the specific settings and properties of each entity, the status of the specific entity and so on.

The PowerShell commands that we review in the current article are:

  • Get-MigrationEndpoint
  • Get-MigrationBatch
  • Get-MoveRequest
  • Get-MoveRequestStatistics
  • Get-MigrationUser
  • Get-MigrationUserStatistics

In the following diagram, we can see that PowerShell cmdlets that are associated with the user account object” and the Exchange mailbox object.

The entities that involved in the mailbox migration to Office 365 and the associated PowerShell commands -01

In the following diagram, we can see that PowerShell cmdlets that are associated with the migration batch object” and the migration endpoint object.

The entities that involved in the mailbox migration to Office 365 and the associated PowerShell commands -02

The Migration batch object as a logical container

An additional concept that I would like to mention regarding the mailbox migration entities is the concept of the “Migration batch”.

We can relate to the “Migration batch entity” as a logical container, that “hold inside” the migrated mailbox and the users accounts that are associated with each Exchange mailbox.

In a case that we run multiple Migration batches at the same time, in some scenarios, we will need to get information about all the migration entities that are related to the specific Migration batch.

In the next articles –Using PowerShell for view and export information about mailbox migration to Office 365 | Part 3#5 and Using PowerShell for view and export information about mailbox migration to Office 365 | Part 4#5, we review the PowerShell commands that we can use for getting information about objects such as “Move Requests” and “Migration users that are related to a specific Migration batch.

Migration Batch as a logical container

A short description of the migration entities

Migration Endpoint
Get-MigrationEndpoint
The term “Endpoint” or “Migration EndPoint”, define a set of settings and credentials that Exchange Online use for “addressing” the Exchange on-Premises server.
Each mailbox migration process (migration batch) must use an existing “Migration Endpoint”, that serve as the base for the mailbox migration process.
In other words – in case that the “Migration EndPoint”, was not created or in case that the Endpoint includes wrong settings such as wrong credentials or wrong Exchange on-Premises server name, the mailbox migration process cannot be executed.
Exchange Online support the option of using multiple “Migration EndPoints”.
Migration Batch
Get-MigrationBatch
The term “migration batch” serve for define a “logical container”, that contain one or many “move requests”, and the user accounts that are associated with each migrated mailbox.
In Office 365 (Exchange Online) environment, most of the time, the term “Migrated mailbox”, relates to Exchange on-Premises mailbox that is migrated to the cloud (Exchange Online).
In Exchange Hybrid environment, the term “Migrated mailbox” could also relate to “off boarding”, a scenario in which the mailbox migration is implemented by migrating Exchange Online mailbox to the Exchange on-Premises environment.
Move Request
Get-MoveRequest Get-MoveRequestStatistics
The term “Move Request” describe the process in which the Exchange on-Premises mailboxes is “copied” and then “moved” to the Office 365 (Exchange Online).
The PowerShell commands that relate to the “Move Request” are:
  • Get-MoveRequest

The PowerShell command Get-MoveRequest will “fetch” information about the mailbox properties that we migrate.

  • Get-MoveRequestStatistics

The PowerShell command Get-MoveRequestStatistics will “fetch” more detailed information about the “mailbox content” that we migrate.
For example, information about the completed percentage of mailbox content that was migrated, errors, information about “bad mail items” and more.

MigrationUser
Get-MigrationUser MigrationUserStatistics
Each Exchange mailbox is associated with a “user account”.
The PowerShell command Get-MigrationUser , will “fetch” information about the user account properties that is associated with the Exchange mailbox.
The PowerShell command Get-MigrationUserStatistics, will “fetch” additional information such as – SyncedItemCount ,Status ,EstimatedTotalTransferSize and more.

The scope of the article series

The basic assumption is that in this phase you have already mange to create the required “Exchange on-Premises endpoint”.

The meaning is, that your Exchange on-Premises server have all the required prerequires such a public availability”, that enable Exchange Online to establish the connection with your Exchange on-Premises server.

In case that you need to “establish” the connection between Exchange Online and Exchange on-Premises, and you need more information about the required preparations and prerequires you can read the following articles:

You can read additional information about the process of creating migration endpoint in the following articles:

The various type of mail migration to Office 365

At the current time, Exchange Online support the following types of mailbox migration

  1. Cutover migration
  2. Stage migration
  3. Exchange Hybrid migration
  4. IMAP migration

Although that each of the “Exchange Online mail migration method have unique characters of its own, the PowerShell command that we review are relevant for all the above mail migration methods.

Additional reading

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

Restore Exchange Online mailbox | Article series index

Please rate this

The post Mailbox migration to Office 365 the PowerShell migration entities | Part 1#5 5/5 (2) appeared first on o365info.com.

Using PowerShell for view and export information about mailbox migration to Office 365 | Part 4#5 5/5 (1)

$
0
0

The current article is the continuation of the former article, in which we review the various PowerShell cmdlets that we can use for viewing, and export information about the process of Exchange mailbox migration process.

The “mailbox migration” PowerShell commands that we review in this article are:

  • Get-MigrationStatistics
  • Get-MigrationUser
  • Get-MigrationUserStatistics

In addition, we review the PowerShell commands that we can use for getting information about on-Premises environment

1. Migration Statistics | Get-MigrationStatistics

Get + Export Information | Migration Statistics

The PowerShell command Get-MigrationStatistics, provide us information about the migration process using properties such as – Synced Count,Total Count and more.

Get information about Migration Statistics

PowerShell command syntax

Get-MigrationStatistics -Diagnostic

PowerShell console output example

PS C:\> Get-MigrationStatistics -Diagnostic

MigrationType      TotalCount FailedCount SyncedCount
-------------      ---------- ----------- -----------
ExchangeRemoteMove 4          0           0

Get + Export information about Migration Statistics | Example

Get-MigrationStatistics -Diagnostic |Format-List | Out-File c:\temp\"Get-MigrationStatistics -Diagnostic.txt" -Encoding UTF8

Additional reading

Get-MigrationStatistics

Migration Users

Get + Export Information | Migration Users

As mentioned, each Exchange mailbox must have a “user account” that is associated with the mailbox (mailbox owner).

The PowerShell command that we use for getting information about the user account that is “attached” to the mailbox that we migrate are:

  • Get-MigrationUser
  • Get-MigrationUserStatistics

2. Get migraiotion user information | Get-MigrationUser

The PowerShell command – Get-MigrationUser, display information about the user account properties that is associated with the Exchange mailbox that we migrate + high level information about the mailbox migrated content.

Get information about specific “Migration User”

PowerShell command syntax

Get-MigrationUser <Migrated user account>

PowerShell console output example

PS C:\> Get-MigrationUser onpremmbx-01@o365info.com

Identity                                 Batch                          Status                    LastSyncTime                                                                                                                 
--------                                 -----                          ------                    ------------                                                                                                                 
onpremmbx-01@o365info.com                Eyal Migration batch -001      Completed                 2/23/2017 10:47:28 AM

Export information about specific “Migration User” | TXT File

Get-MigrationUser onpremmbx-01@o365info.com |Format-List | Out-File c:\temp\"Get-MigrationUser - onpremmbx-01@o365info.com.txt" -Encoding UTF8

Export information about ALL “migration users” | TXT File

To get information about ALL “migration users” + export the information to text file, we can use the PowerShell command example:

PowerShell command example

Get-MigrationUser | Format-List | Out-File c:\temp\"Get-MigrationUser.txt" -Encoding UTF8

Export information about ALL “migration users” | View specific properties | TXT File

If we want to “refine” the result and view the most relevant information we can use the following PowerShell syntax:

PowerShell command example

Get-MigrationUser | Select Identity,RecipientType,SkippedItemCount,SyncedItemCount,Status,BatchId,LastSuccessfulSyncTime | Out-File c:\temp\"Get-MigrationUser.txt" -Encoding UTF8

3. Get migraiotion user Statistics information | Get-MigrationUserStatistics

The PowerShell command Get-MigrationUserStatistics will get us additional information about “migrated user” that is associated with the mailbox that we migrate + more detailed information about the mailbox content meaning, mail items that are migrated.

Get information about specific “Migration User Statistics”

PowerShell command syntax

Get-MigrationUserStatistics <Migrated user account>

PowerShell console output example

PS C:\> Get-MigrationUserStatistics onpremmbx-01@o365info.com

Identity                                 Batch                          Status                    Items Synced     Items Skipped   
--------                                 -----                          ------                    ------------     -------------   
onpremmbx-01@o365info.com                Eyal Migration batch -001      Completed                 4                0

Export information about specific “Migration User Statistics” | TXT File

Get-MigrationUserStatistics onpremmbx-01@o365info.com | Format-List | Out-File c:\temp\"Get-MigrationUser.txt" -Encoding UTF8

Export information about specific “Migration User Statistics” + more detailed information | TXT File

In this scenario, we add the following additional parameters: IncludeReport , Diagnostic and IncludeSkippedItems that could help us to get more details.

PowerShell command example

Get-MigrationUserStatistics onpremmbx-01@o365info.com -IncludeReport -Diagnostic -IncludeSkippedItems | Format-List | Out-File c:\temp\"Get-MigrationUser.txt" -Encoding UTF8

Export “Migration User Statistics” All Migration User + Detailed information | XML File

In this scenario, we get the most detailed Statistics information about ALL the existing “Migration Users” and export the information to XML file.

PowerShell command example

Get-MigrationUserStatistics -IncludeReport -Diagnostic -IncludeSkippedItems| Export-CliXml c:\temp\"Get-MigrationUserStatistics -IncludeReport -Diagnostic.xml" -Encoding UTF8

5. On-Premise infrastructure information

The current article series is dedicated to the Office 365 and Exchange Online environment but in some troubleshooting scenario, we will need to get more information about the “on-Premises infrastructure”.

For example, we get migration errors that are related to a specific user, or a specific mailbox.
We suspect that the issue can be realities to a problem with the On-Premise Active Directory user account or, to a “problematic Exchange on-Premises mailbox”.

On-Premise Active Directory

Export information about On-Premise Active Directory user

To get information about specific Active Directory user account + export the information to TXT file we can use the following PowerShell command

PowerShell command example

Get-Aduser onpremmbx-01@o365info.com -Properties * | Format-List | Out-File c:\temp\npremmbx-01@o365info.com -Active Directory  user.TXT

Note – the following PowerShell command, should be executed from the On-Premise environment, using a Domain controller server or a server that include Active Directory PowerShell cmdlets.

Exchange on-Premises infrastructure

To get information about specific Exchange on-Premises mailbox we can use the following two PowerShell commands:

  • Get-Mailbox
  • Get-MailboxStatistics
Note – the following PowerShell command, should be executed from the On-Premise environment, using an Exchange on-Premises PowerShell.

Get-Mailbox PowerShell command

To get information about specific Exchange on-Premises mailbox + export the information to TXT file, we can use the following syntax:

Export information about Exchange on-Premises mailbox

PowerShell command example

Get-Mailbox onpremmbx-01@o365info.com | Format-List | Out-File c:\temp\onpremmbx-01@o365info.com-Get-Mailbox on-Premises.txt

Get-MailboxStatistics PowerShell command

The PowerShell command Get-MailboxStatistics, can help us to get a very detailed information about Exchange mailbox “structure”, that include information about each mailbox folder, the number of mail items in each folder and much more.

Export information about Exchange on-Premises mailbox tatistics | TXT file

Get-MailboxStatistics onpremmbx-01@o365info.com | Format-List | Out-File c:\temp\”onpremmbx-01@o365info.com -Get-MailboxStatistics on-Premises.txt

Export information about Exchange on-Premises mailbox tatistics | CSV file

Get-MailboxStatistics onpremmbx-01@o365info.com –IncludeMoveHistory| Export-CSV c:\temp\"onpremmbx-01@o365info.com -Get-MailboxStatistics on-Premises - IncludeMoveHistory.CSV" –NoTypeInformation -Encoding utf8


For your convenience, I have “Wrapped” all the PowerShell commands that were reviewed in the article,
in a “Menu Based” PowerShell Script.

You are welcome to download the PowerShell script and use it.
Download -o365info PowerShell Script

Using PowerShell for view and export information about mailbox migration to Office 365 5/5 (1)
In case you want to get more detailed information about how to use the o365info menu PowerShell script, you can read the following article

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

Restore Exchange Online mailbox | Article series index

Please rate this

The post Using PowerShell for view and export information about mailbox migration to Office 365 | Part 4#5 5/5 (1) appeared first on o365info.com.

Viewing all 370 articles
Browse latest View live