How to Use Set-DatabaseAvailabilityGroup Cmdlet?

Summary: Set-DatabaseAvailabilityGroup is an Exchange Server PowerShell cmdlet used to configure, manage, or update the properties of Exchange Database Availability Group (DAG). In this article, you will learn how to use the Set-DatabaseAvailabilityGroup cmdlet to manage the DAG and switch or change Witness Server and Witness Directory if the existing one fails to boot.

Set-DatabaseAvailabilityGroup is a PowerShell cmdlet used to make changes to the Database Availability Group (DAG) that can’t be done or performed via Exchange Admin Center (EAC) or Exchange Management Console (EMC). For instance, selecting/changing the TCP port, changing Witness Server and Witness Directory, disabling cross-site RPC client access, configuring network discovery, enabling Datacenter Activation Coordination or DAC mode, etc.

This article discusses how to use the Set-DatabaseAvailabilityGroup cmdlet with various switches and parameters to manage the DAG.

Steps to Use Set-DatabaseAvailabilityGroup Cmdlet

Follow the steps discussed below to learn how to use the Set-DatabaseAvailabilityGroup cmdlet in Exchange Server 2010, 2013, 2016, and 2019.

Step 1: Assign Roles and Permissions

To use Set-DatabaseAvailabilityGroup for managing, configuring, or updating the DAG cluster, you must have the required roles and permissions assigned to your username or account. In addition, you must have the ‘Database Availability Groups‘ role assigned to your user account. To assign this role via Exchange Admin Center, follow these steps:

You may also assign the ‘Database Availability Groups‘ role by using the following PowerShell cmdlet in Exchange Management Shell (EMS) as administrator.

New-ManagementRoleAssignment -Role "Database Availability Groups" -User administrator

This command will assign the required ‘Database Availability Groups’ role to the user ‘administrator.’

Step 2: Set-DatabaseAvailabilityGroup Syntax

Before using the Set-DatabaseAvailabilityGroup cmdlet, you must know the right syntax to avoid errors.

Set-DatabaseAvailabilityGroup -Identity <DatabaseAvailabilityGroupIdParameter>

Step 3: Use the Set-DatabaseAvailabilityGroup Cmdlet

Below, we have discussed the Set-DatabaseAvailabilityGroup cmdlets to perform the following operations in a Database Availability Group.

Set Witness Server and Witness Directory

To set Witness Server and Directory for DAG, you can use the -WitnessServer and ?WitnessDirectory parameters. The command is as follows:

Set-DatabaseAvailabilityGroup -Identity <DatabaseAvailabilityGroupIdParameter> -WitnessServer <FileShareWitnessServerName> -WitnessDirectory <NonRootLocalLongFullPath>

For instance,

Set-DatabaseAvailabilityGroup -Identity "DAG01" -WitnessServer WS3 -WitnessDirectory ?C:\DAG01DIR?

The command sets Witness Server WS3 and Witness Directory C:\DAG01DIR for DAG DAG01. Before executing, make sure to change the path and the DAG name in the command.

Set or Change Witness Directory

To set or change only the Witness Directory for DAG, you can use the -WitnessDirectory parameter.

Set-DatabaseAvailabilityGroup -Identity <DatabaseAvailabilityGroupIdParameter>] -WitnessDirectory <NonRootLocalLongFullPath>

For instance,

Set-DatabaseAvailabilityGroup ?Identity "DAG01" -WitnessDirectory "C:\DAG01DIR"

The command sets Witness Directory C:\DAG01DIR for DAG DAG01. Before executing, make sure to change the path and the DAG name in the command.

Set Alternate Witness Directory and Server

Sometimes when Witness Server fails, you need to set an alternate Witness Server and Directory to maintain Quorum and ensure high availability. In such cases, you can use the –AlternateWitnessDirectory and ?AlternateWitnessServer parameters. The command is as follows:

Set-DatabaseAvailabilityGroup -Identity <DatabaseAvailabilityGroupIdParameter> -AlternateWitnessDirectory <NonRootLocalLongFullPath> -AlternateWitnessServer <FileShareWitnessServerName>

For instance,

Set-DatabaseAvailabilityGroup -Identity DAG01 -AlternateWitnessDirectory C:\DAG02DIR -AlternateWitnessServer WS4

The command sets WS4 and C:\DAG02DIR as alternate Witness Server and Witness Directory respectively for the DAG DAG01.

Configure DAG to Use DHCP for Obtaining IP Address

Since member servers can be resolved by their names, you can setup and configure the member servers in a DAG to obtain the IP addresses automatically. To do this, use the ?DatabaseAvailabilityGroupIpAddresses parameter. The syntax is as follows:

Set-DatabaseAvailabilityGroup -Identity <DatabaseAvailabilityGroupIdParameter> -DatabaseAvailabilityGroupIpAddresses <IPAddress[]>

For instance,

Set-DatabaseAvailabilityGroup -Identity DAG01 -DatabaseAvailabilityGroupIpAddresses 0.0.0.0

This configures the DAG DAG01 to obtain the IP addresses automatically from the network adapter or router.

Assign Static IP to DAG Members

Although assigning static IP isn’t a requirement as long as the name can resolve the DAG member servers, you can assign static IP to each DAG member if needed or based on your organization’s preferences using the -DatabaseAvailabilityGroupIpAddresses parameter.

The command is as follows:

Set-DatabaseAvailabilityGroup -Identity DAG01 -DatabaseAvailabilityGroupIpAddresses 192.168.0.8

The above command sets Static IP 10.0.0.8 to the DAG DAG01. In addition, you can also configure DAG DAG01 with multiple Static IP addresses using the following command. 

Set-DatabaseAvailabilityGroup -Identity DAG01 -DatabaseAvailabilityGroupIpAddresses 192.168.0.8,192.168.1.8

Configure the TCP Port for Replication

By default, all DAG members use the 64327 port for continuous replication. However, you can always modify the port to a different TCP port by using the -ReplicationPort parameter.

Set-DatabaseAvailabilityGroup -Identity <DatabaseAvailabilityGroupIdParameter> -ReplicationPort <UInt16>

For instance,

Set-DatabaseAvailabilityGroup -Identity DAG01 -ReplicationPort 32400

The command sets the TCP port to 32400. You can change it to any open or available port.

Enable or Disable DAC Mode

Database Activation Coordination (DAC) mode is a DAG feature?disabled by default ?that controls the database mount behavior on the DAG startup. It avoids split-brain situations (inconsistencies) that may activate two copies on two member servers on the same DAG.

You should enable DAC mode for DAG with two or more members using continuous replication. However, avoid enabling the DAC mode for your DAG infrastructure if you use a third-party replication mode. The parameter used to enable or disable DAC mode is ?DatacenterActivationMode.

Set-DatabaseAvailabilityGroup -Identity <DatabaseAvailabilityGroupIdParameter> -DatacenterActivationMode <DatacenterActivationModeOption>

For instance,

Set-DatabaseAvailabilityGroup -Identity DAG01 -DatacenterActivationMode DagOnly
Set-DatabaseAvailabilityGroup -Identity DAG01 -DatacenterActivationMode off

The former command enables the DAC mode while the latter turns off the DAC mode for DAG DAG01.

Other Set-DatabaseAvailabilityGroup Switches and Parameters

We have already covered the most common and important parameters that you need to know when it comes to using the Set-DatabaseAvailabilityGroup cmdlet.

In addition, there are several other parameters and switches that you can use with the Set-DatabaseAvailabilityGroup cmdlet. However, many of them are reserved for internal Microsoft use while others may require additional permissions to run. To learn more, you can refer to this Microsoft Documentation.  

Tip: If you encounter issues with your DAG member server, use Restore-DatabaseAvailabilityGroup to activate a DAG member server in a cluster when it goes down after Quorum is lost.

Conclusion

If the Set-DatabaseAvailabilityGroup cmdlet fails to configure or change the Witness Server or Witness Directory, the Quorum will no longer be maintained and may be lost. This may damage the Database Availability Group and cause inconsistencies in the member server or database. In such a case, you must set up a new DAG infrastructure and add the servers to the new DAG. You can then restore the database and mailboxes from backup or use a third-party Exchange recovery software, such as Stellar Repair for Exchange, to move the mailboxes from the old DAG member servers to new ones. The software can help extract the mailboxes and items from the database on the failed Exchange DAG member servers to PST files. You may also directly export the mailboxes recovered from the database to a new live Exchange member server or Office 365.

Related Post