Search
StarWind is a hyperconverged (HCI) vendor with focus on Enterprise ROBO, SMB & Edge

Managing Exchange Server 2016 Using PowerShell

  • March 1, 2017
  • 15 min read
IT Production Manager. Nicolas is primarily focused on Microsoft technologies, he is a Microsoft MVP in Cloud and Datacenter Management.
IT Production Manager. Nicolas is primarily focused on Microsoft technologies, he is a Microsoft MVP in Cloud and Datacenter Management.

Exchange Server 2016 Using PowerShell

PowerShell has become the preferred tool for managing Microsoft server products. Sysadmins can take full advantage of PowerShell to manage roles and perform routine management tasks. By using the command line, sysadmins are able to:

  • Create a mailbox
  • Configure a receive connector
  • Generate a custom report
  • Manage Distribution Group members, permissions, and group types
  • Manage Exchange Services
  • Etc.

In this article, we will not cover all the Exchange Management cmdlets, but I will describe several examples to guide you in the right direction. In all Exchange Server edition, a lot of settings are configured automatically by the Exchange installation. So, it is a good idea to explore all the settings individually to become familiar with your Exchange Server.

Exchange Management Shell

Thanks to the previous article, you have everything installed. Now it’s time to configure your Exchange server using the Exchange Management Shell console. What is it? EMS (Exchange Management Shell) is based on Microsoft Windows PowerShell, which provides a powerful command-line interface for executing and automating administrative tasks. With the Exchange Management Shell, you can manage every aspect of Exchange Server 2016.

How to run the Exchange Management Shell?

Let’s take a look at a couple of ways that you can use the EMS in a scripting environment. When you install an Exchange Server, you get the Exchange tools installed along with it which gives you the EMS.

Exchange tools in the Exchange Server

Click Start > Microsoft Exchange Server 2016 > Exchange Management Shell.

Exchange Management Shell

As you can see, it is just a customized version of “powershell.exe” that will load the Exchange PowerShell module. You may want to connect manually to your Exchange server from the PowerShell console. So, let’s start by creating a PowerShell Session:

You need to manually specify the server you want to connect to. Next, you should be able to use the Import-PSSession cmdlet to load the Exchange module:

Import-PSSession cmdlet to load the Exchange module

Now, you can compare both consoles by running the Get-Mailbox cmdlet to list all the mailboxes on your Exchange Server and confirm that the result is the same:

Get-Mailbox cmdlet

Which one do you have to use? Well, it’s up to you!

Checking the Microsoft Exchange Server Status

Before configuring Exchange, we will just check that Exchange Services are started:

Microsoft Exchange Server Status

I don’t want to use IMAP and POP, so these Windows Services are stopped. Now, we can check some useful information about our Exchange Server:

cmdlet for Exchange Server

How to know which cmdlets are available to configure Exchange?

When you open the console, EMS shows you some useful tips. So you can run this command to display only Exchange cmdlets:

Exchange cmdlets

You can get the full list on the TechNet website:

https://technet.microsoft.com/en-us/library/bb124413(v=exchg.160).aspx

Configuring Exchange Server 2016

Now, we can start by configuring accepted domains and email address policies. Accepted domains are the SMTP namespaces that you configure to receive email messages. To create an accepted domain, use the following command:

 

command for configutring accepted domain

We can verify that we have successfully created an accepted domain and make it the default domain.

checking accepted domain

Use the New-EmailAddressPolicy cmdlet to create e-mail address policies:

Exchange requires you to use variables to define the local part of the email address. These variables are described in the following table (from the TechNet website):

variables to define the local part of the email address

Get email adress policy command

Connectors

You must create a send connector to route outbound mail to the Internet. I advise you to route outbound mail through a smart host (Antispam Gateway).

This connector will send email messages over the Internet. The -FrontendProxyEnabled parameter is set to True. This means that Exchange will actually proxy outbound emails through the CAS server to the Internet.

New Send Connector command

Please note the following information:

  • Exchange does not automatically create a default send connector
  • A basic connector will send out to the Internet via DNS resolution

Note that if you want to test SMTP connectors on Exchange, you can run the following command:

Exchange Server 2016 uses receive connectors to control inbound SMTP connections from messaging servers that are external to your Exchange Organization. Exchange creates a default receive connector:

Get Receive Connector command

But if you need to create a new one, use the following:

Monitoring Exchange Server

How to check the content of an email queue?

It is good to know how to check an email queue. This is useful to determine if the mail flow is fluent or not. There are three types of queues available on Exchange Servers:

  • Submission: Messages waiting to be processed by transport agents
  • Unreachable: Messages that could not be delivered to their destination
  • Poison message: Messages classified as dangerous for the server.

To check the contents of the submission queue run the following command:

Get Queu Identify Submission command

Exchange Server has some useful logs that you can check. Use the Get-MessageTrackingLog cmdlet to search for message delivery information stored in the message tracking log.

You can also count the total email messages processing by Exchange Server:

Get message tracking log command

Some months ago, I wrote two PowerShell scripts. The first one lets you perform a query in the message tracking log from a GUI. This script is available on the Microsoft TechNet Gallery: https://gallery.technet.microsoft.com/Exchange-2013-Message-875b3eeb

Message tracking log gui

And the second one is a health check for your Exchange environment: https://gallery.technet.microsoft.com/Exchange-2013-Audit-and-7e16fba5

StarWind HyperConverged Appliance is a turnkey, entirely software-defined hyperconverged platform purpose-built for intensive virtualization workloads. Bringing the desired performance and reducing downtime, the solution can be deployed by organizations with limited budgets and IT team resources. Also, it requires only one onsite node to deliver HA for your applications that make the solution even more cost-efficient.
Find out more about ➡ StarWind HyperConverged Appliance

Mailbox and Distribution Group Management

There are different types of the recipient in Exchange Server 2016. After installing Exchange 2016, you can create user mailboxes which is one of the most commonly used mailbox types. But you can also create resource mailboxes and distribution groups. Let’s see some examples:

Create user mailbox

Read host command

Create resource mailbox

Create resource mailbox command

Create equipment mailbox

Create equipment mailbox command

Create distribution group

Create distribution group command

Remember that for a New-* cmdlet, there are often (but not always) Get-* and Set-* cmdlets available.

Managing Outlook/OWA Configuration

Finally, most of Outlook’s Exchange specific functionalities such as Automatic Replies (also known as “Out of Office Assistant” or “OOF”) can also be configured using EMS. For example, Exchange Administrators can enable automatic replies for another user without logging on to the mailbox by using the Set-MailboxAutoReplyConfiguration cmdlet:

Conclusion

With more than 1000 cmdlets at your disposal, there is plenty that you can do with PowerShell and Exchange. I can’t cover all these cmdlets, but the idea of this article was to describe several examples and explain how PowerShell can help you in your day-to-day sysadmin tasks. Thanks to PowerShell, you can now easily create a script to deploy and configure automatically Exchange Server 2016 in a new environment.

Thanks for reading!

Hey! Found Nicolas’s article helpful? Looking to deploy a new, easy-to-manage, and cost-effective hyperconverged infrastructure?
Alex Bykovskyi
Alex Bykovskyi StarWind Virtual HCI Appliance Product Manager
Well, we can help you with this one! Building a new hyperconverged environment is a breeze with StarWind Virtual HCI Appliance (VHCA). It’s a complete hyperconverged infrastructure solution that combines hypervisor (vSphere, Hyper-V, Proxmox, or our custom version of KVM), software-defined storage (StarWind VSAN), and streamlined management tools. Interested in diving deeper into VHCA’s capabilities and features? Book your StarWind Virtual HCI Appliance demo today!