共用方式為


Automating updating of Exchange configuration files

When configuring the Transport Role in Exchange 2010, you often change the paths of the Queue Database and Logs. This is done by editing the EdgeTransport.exe.config file. This is a tedious task if deploying multiple servers and the risk of typo’s is always present when doing manual editing.

To automate this, use Powershell to parse and edit the file for you, as shown in the example below. Non-default installation path is used, so modify to suit your needs. The same code can be used when updating web.config or other configuration files.

 

$TransportConfig = "\D$\Exchange\Bin\EdgeTransport.exe.config"

$FullServerName = “server1.contoso.com”

$newcontent = ""

$RemoteFile = "\\" + $FullServerName + $TransportConfig
(Get-Content $RemoteFile) | Foreach-Object {
    $line = $_
    if ($line -like "*QueueDatabasePath*") {$line = '      <add key="QueueDatabasePath" value = "E:\Exchange\TransportRoles\data\Queue" />' }
    if ($line -like "*QueueDatabaseLoggingPath*") {$line = '      <add key="QueueDatabaseLoggingPath" value = "E:\Exchange\TransportRoles\data\Queue" />'}
    if ($line -like "*TemporaryStoragePath*") {$line = '      <add key="TemporaryStoragePath" value = "E:\Exchange\TransportRoles\data\Temp" />'}
    $newcontent += $line + [char]13 + [char]10
}
Set-Content $RemoteFile $newcontent

 

Hope this will save you some time configuring Exchange.