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

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
主站蜘蛛池模板: 金门县| 云安县| 麻栗坡县| 新和县| 胶南市| 安平县| 恩施市| 绥棱县| 远安县| 博野县| 宜昌市| 安远县| 沅陵县| 陆丰市| 噶尔县| 石泉县| 和林格尔县| 商河县| 新建县| 林西县| 长武县| 剑阁县| 神农架林区| 卓尼县| 青海省| 溆浦县| 龙里县| 屯昌县| 社旗县| 绥棱县| 维西| 万山特区| 无锡市| 彩票| 宜城市| 寿阳县| 华蓥市| 张家口市| 四会市| 元氏县| 玉林市|