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

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
主站蜘蛛池模板: 商南县| 库尔勒市| 吉水县| 灵山县| 泰宁县| 九江市| 苗栗市| 凤台县| 秦安县| 天门市| 石嘴山市| 新宁县| 诏安县| 阿瓦提县| 沙洋县| 合作市| 恩施市| 梁河县| 塔河县| 黄梅县| 三明市| 临武县| 唐海县| 大余县| 泰安市| 分宜县| 磐安县| 祁阳县| 铜鼓县| 白城市| 绥滨县| 台江县| 梓潼县| 荥经县| 娄底市| 松阳县| 两当县| 罗源县| 鹤岗市| 泾阳县| 嘉黎县|