Automate Exchange 2016 installation and DAG configuration with PowerShell DSC


Hi, folks!

Version 1.0 has already been published here (simple script for automation of Exchange 2016 installation. can be used on multiple servers).

Today’s version is a little bit improved (2 separate files for 2-node configuration, 535 and 420 strings respectively, can be easy scaled out with copy-paste to more than 2 nodes). It helps you to install Exchange, prepare environment for DAG (prestage CNO, witness and etc) and create one with at least 2 members

Each node can be configured simultaneously (it’s not needed to wait while fist node finishes all tasks and etc. just run both scripts, relax and get a cup of coffee). It’s also ideally suitable for using as a part of VMM Service Templates or other kinds of unattended installations (I’ll show you it later)

If you’d like to get script files – write me directly or leave request in the comments. I’ll send you zip-file.

What does script do (exch01.ps1)?

  • Sets network settings (DNS, IP, GW) on targeted server
#..........
xIPAddress NewIPAddress #Set IPv4 on Ethernet adapter
        {
            IPAddress      = $ip
            InterfaceAlias = "Ethernet"
            SubnetMask     = 24
            AddressFamily  = "IPV4"
            DependsOn       = "[xDhcpClient]DisabledDhcpClient"
        }
         xDefaultGatewayAddress GW #Set GW address
        {
            Address = $gw
            InterfaceAlias = "Ethernet"
            AddressFamily = "IPv4"
            DependsOn     = "[xIPAddress]NewIPAddress"
        }
#...........
  • Installs required prerequisites for Exchange (including UCMA) and does reboot if it’s really required
#........
 WindowsFeature WebNet45
        {
            Ensure = 'Present'
            Name = 'Web-Net-Ext45'
        }
     WindowsFeature WebReq
        {
            Ensure = 'Present'
            Name = 'Web-Request-Monitor'
        }
     WindowsFeature WebSrv
        {
            Ensure = 'Present'
            Name = 'Web-Server'
        }
#.........
  • Adds server to domain and reboots it to apply changes
 xComputer DomainJoin
        {
          Name = $nodename
          DomainName = $domainname
          Credential = $creds
          DependsOn  = "[xDnsServerAddress]DNSServers"
        }
  • Setups Exchange and checks if reboot is required after installation
 xExchInstall InstallExchange
        {
            Path       = "C:\ExchInstall\Exch\Setup.exe"
            Arguments  = "/mode:Install /role:Mailbox /OrganizationName:""$netbios"" /Iacceptexchangeserverlicenseterms"
            Credential = $Creds

            DependsOn  = '[xPendingReboot]BeforeExchangeInstall'
        }
  • Adds and checks that DAG CNO is existed and required permissions are applied
#...........
SetScript = {
                    $creds = New-Object Management.Automation.PSCredential("$($using:netbios)\Administrator",(ConvertTo-SecureString $using:pass -AsPlainText -Force))
                    New-ADComputer -Name DAG01 -DNSHostName DAG01 -DisplayName DAG01 -Enabled $false -Credential $creds -verbose
                    $DC=(Get-ADDomainController -Credential $creds).HostName
                    ICM -ComputerName $DC -Credential $creds -ScriptBlock {
                    #Variables
                    $dagacc = Get-ADComputer DAG01 #-Credential $creds
                    $dagldap="LDAP" + '://' + $dagacc.DistinguishedName
                    $dagadsi = New-Object DirectoryServices.DirectoryEntry $dagldap
                    #.....
                    }
#...........
  • Configures witness server, DAG and generates status of successful completion
#........
xExchDatabaseAvailabilityGroup DAG
        {
            Name                                 = $dagSettings.DAGName
            Credential                           = $creds
            AutoDagTotalNumberOfServers          = $dagSettings.AutoDagTotalNumberOfServers
            AutoDagDatabaseCopiesPerVolume       = $dagSettings.AutoDagDatabaseCopiesPerVolume
           #.......
            WitnessDirectory                     = 'C:\FSW'
            WitnessServer                        = $dagSettings.WitnessServer
        }
#.........

Script file named as exch02.ps1 has almost the same steps with the following differences:

  1. Waits while Exchange setup initiated on the first node finishes Active Directory preparation and then starts Exchanges installation on the second node
  2. Waits while DAG becomes online and only then starts adding the second node
  3.  No witness and DAG CNO preparation (hope it’s clear)

Requirements are still the same: exchange media, UCMA package, certificates for securing MOF-files (optional). All prerequisites (except Exchange media files) are in the zip-file (all-in-one).

Thanks for reading and have a nice week!

4 thoughts on “Automate Exchange 2016 installation and DAG configuration with PowerShell DSC”

      1. Hi Roman,

        Nice job – i am still trying to wrap my head around DSC and how the xExchange modules can be used. I see xExchange is now expanded and has many other modules plus full end to end examples.

        So the way it works is that you push 1 script which does the pre-reqs, then you push another script that does the install and then you do other scripts/mofs that do the post install configs such as DAGs or other Exchange settings right? But doing it via DSC has the benefit of maintaining that configuration going forward, so if we are running 1 DSC script after another, doesnt it lose the value because the config to maintain is the last script that was pushed or they somehow stack up?

        maybe if you could send me the scripts, ill understand it better…

        Thank you!

        1. Kamil, thanks for the feedback.

          In short, I use 2 scripts and they are linked to the different servers. I don’t push all 2 configuration files to 1 server . Step 1 is just applying initial configuration on the first node + DAG creating. Step 2 (file 2) – pushing this script file to the second node and adding it to the DAG. How DSC works with configurations? It depends on LCM settings (Get-DSCLocalConfigurationManager, refresh mode/configuration mode/partial and etc)

          P.S. use contact page for request. I’ve not got your email address..

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s