官术网_书友最值得收藏!

Scripting an Exchange server installation

If you are performing mass deployment of Exchange servers in a large environment, automating the installation process can minimize administrator error and speed up the overall process. The setup.exe utility can be used to perform an unattended installation of Exchange, and when combined with PowerShell and just a little bit of scripting logic, it can create a fairly sophisticated installation script. This recipe will provide a couple of examples that can be used to script the installation of an Exchange server.

Getting ready

You can use a standard PowerShell console from the server to run the scripts in this recipe.

How to do it...

Let's see how to create an automated installation script that installs Exchange based on the hostname of the server:

  1. Using Notepad or your favorite scripting editor, add the following code to a new file:
    Param($Path)
    if(Test-Path $Path) {
      switch -wildcard ($env:computername) {
        "*-EX-*" {$role = "CA,MB" ; break}
        "*-MB-*"  {$role = "MB" ; break}
        "*-CA-*"  {$role = "CA" ; break}
      }
      $setup = Join-Path $Path "setup.exe"
      Invoke-Expression "$setup /mode:install ` /r:$role /IAcceptExchangeServerLicenseTerms ` /InstallWindowsComponents"
    }
    else {
      Write-Host "Invalid Media Path!"
    }
  2. Save the file as InstallExchange.ps1.
  3. Execute the script from a server, where you want to install Exchange using the following syntax:
    InstallExchange.ps1 -Path D:
    

The value provided for the -Path parameter should refer to the Exchange 2013 media, either on DVD or extracted to a folder.

How it works...

One of the most common methods to automate an Exchange installation is to determine the required roles based on the hostname of the server. In the previous example, we assume that your organization uses a standard server naming convention. When executing the script, the switch statement will evaluate the hostname of the server and determine the required roles. For example, if your mailbox servers use a server name, such as CONTOSO-MB-01, the mailbox server role will be installed. If your CAS servers use a server name, such as CONTOSO-CA-02, the CAS role will be installed, and so on.

It's important to note that Exchange 2013 requires several Windows operating system hotfixes, such as .NET Framework 4.5, Filter Pack 2.0, and Unified Communications API 4.0. These should all be installed prior to running this script.

When calling the Setup.exe installation program within the script, we use the /InstallWindowsComponents and /IAcceptExchangeServerLicenseTerms switches, which are new Setup.exe features in Exchange Server 2013. This will allow the setup program to load any prerequisite Windows roles and features, such as IIS, and so on, before starting the Exchange installation. The accept agreement switch is required when using the unattended installation method.

There's more...

Scripting the installation of Exchange based on the server names may not be an option for you. Fortunately, PowerShell gives us plenty of flexibility. The following script uses a similar logic, but performs the installation based on different criteria.

Let's say that your core Exchange infrastructure has already been deployed. Your corporate headquarters already has the required CAS and Hub Transport server infrastructure in place; and therefore, you only need to deploy mailbox servers in the main Active Directory site. All remaining remote sites will contain multirole Exchange servers. Replace the code in the InstallExchange.ps1 script with the following:

param($Path)
$site = [DirectoryServices.ActiveDirectory.ActiveDirectorySite]
if(Test-Path $Path) {
  switch ($site::GetComputerSite().Name) {
    "Headquarters" {$role = "MB"}
    Default {$role = "CA,MB"}
  }
  $setup = Join-Path $Path "setup.exe"
  Invoke-Expression "$setup /mode:install /r:$role /IAcceptExchangeServerLicenseTerms /InstallWindowsComponents"
}
else {
  Write-Host "Invalid Media Path!"
}

This preceding example determines the current Active Directory site of the computer executing the script. If the computer is in the Headquarters site, only the Mailbox role is installed. If it is located at any of the other remaining Active Directory sites, the Client Access and Mailbox server roles are installed.

As you can see, combining the Setup.exe utility with a PowerShell script can give you many more options when performing an automated installation.

See also

  • Looping through items in Chapter 1, PowerShell Key Concepts
  • Creating custom objects in Chapter 1, PowerShell Key Concepts
  • Working with Desired State Configuration in Chapter 1, PowerShell Key Concepts
主站蜘蛛池模板: 广州市| 沈阳市| 哈巴河县| 鄂尔多斯市| 东源县| 柳州市| 城固县| 芒康县| 万盛区| 伊川县| 霍山县| 松阳县| 区。| 彭山县| 兴文县| 黄骅市| 庆城县| 德格县| 阳江市| 桐梓县| 洛南县| 阳信县| 中卫市| 铁岭市| 沙坪坝区| 囊谦县| 榆中县| 黎平县| 鄯善县| 从江县| 镇康县| 托克逊县| 柳林县| 怀仁县| 柏乡县| 茌平县| 沾化县| 逊克县| 博罗县| 霍邱县| 开鲁县|