Восстановление интеграции OWA и Lync после установки CU на Exchange сервер


При настройке интеграции OWA (Outlook Web Access) и Lync (Skype for Business) необходимо внести изменения в один из файлов web.config.

При установке кумулятивных обновлений происходит перезапись файлов конфигурации, в том числе и этого web.config. В результате интеграция OWA и Lync разрушается.

Есть достаточно удобный скрипт Configure-IMIntegration.ps1, который позволяет быстро восстановить интеграцию. Я доработал этот скрипт и отправил автору: возможно он выложит новую версию (старше 1.0), если нет, то размещу её в этом посте.

<#
	.SYNOPSIS
	Configures IM Integration on Exchange 2013 servers with the Mailbox server role
    that have a valid certificate assigned for UM services, and optionally can configure
    all CAS servers.
       
   	Michel de Rooij
	michel@eightwone.com
	http://eightwone.com
	
	THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE 
	RISK OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER.
	
	Version 1.0, December 25th, 2014

    Special thanks to: Maarten Piederiet
	
	.DESCRIPTION
	Configured IM integration by modifying the web.config file on Mailbox servers
    with the UM assigned certificate and specified Lync Pool FQDN. Uses WMI to remotely
    restart the OWA app pool.
    
    .PARAMETER Server
    Specifies server to configure. When omitted, will configure local server. This
    parameter is mutually exclusive to AllMailbox.

    .PARAMETER AllMailbox
    Specifies to configure all Mailbox servers. This switch is mutally exclusive 
    with Server.

    .PARAMETER PoolFQDN
    Specifies the Lync Pool FQDN

    .PARAMETER AllCAS
    Instructs the script to (re)configure all Client Access Servers for IM. 

	.LINK
	http://eightwone.com

	Revision History
	---------------------------------------------------------------------
	1.1    Ilya Sazonov: fix error, add -Whatif and so on
	1.0    Initial release
	
	.EXAMPLE
    This configures IM integration on all Mailbox servers and CAS servers for lync.contoso.com
	Configure-IMIntegration.ps1 -PoolFQDN lync.contoso.com -AllMaibox -AllCAS
    
    .EXAMPLE
    This configures IM integration on the specified server for lync.contoso.com
	Configure-IMIntegration.ps1 -Server mbx1.contoso.com -PoolFQDN lync.contoso.com

#>
#Requires -Version 3.0

[cmdletbinding(SupportsShouldProcess = $true, DefaultParameterSetName= 'Local')]
param(
	[parameter( Mandatory=$true, ParameterSetName = 'Server')]
	[parameter( Mandatory=$false, ParameterSetName = 'Local')]
		[string]$Server= $env:ComputerName,
	[parameter( Mandatory=$true, ParameterSetName = 'Server')]
	[parameter( Mandatory=$true, ParameterSetName = 'Local')]
	[parameter( Mandatory=$true, ParameterSetName = 'All')]
# Changed!!!
		[string]$PoolFQDN=$(throw "Lync Pool FQDN not specified."),
	[parameter( Mandatory=$false, ParameterSetName = 'Server')]
	[parameter( Mandatory=$false, ParameterSetName = 'Local')]
	[parameter( Mandatory=$false, ParameterSetName = 'All')]
        [switch]$AllCAS,
    [parameter( Mandatory=$true, ParameterSetName = 'All')]
        [switch]$AllMailbox
)

begin {

# Changed!!! (Moved)
    function Configure-WebConfigItem( [ref]$wc, $key, $value) {
        $Node=$wc.Value.configuration.appsettings.SelectSingleNode("add[translate(@key,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='"+$key.ToLower()+"']")
        if (!$Node) {
            Write-Verbose "WebConfig: Adding Key $key, value $value"
            $Node = $wc.value.CreateElement('add')
            $Node.SetAttribute('key', $key)
            $Node.SetAttribute('value', $value)
            $wc.value.configuration.appSettings.AppendChild( $Node) | Out-Null
        } else {
            Write-Verbose "WebConfig: Setting Key $key, value $value"
            $Node.SetAttribute('value', $value)
        }
    }

    If( $AllMailbox) {
        $ServerList= Get-MailboxServer
    }
    Else {
        If( -not ( Get-MailboxServer -Identity $Server)) {
# Changed!!!
            Throw "Server $Server does not run the Mailbox server role."
        }
        $ServerList= @( $Server)
    }


# Changed!!!
    If( -not (Get-Command Get-ExchangeServer -ErrorAction SilentlyContinue)) {
        Throw  "Exchange Management Shell not loaded"
    }

}
process {

    ForEach( $Identity in $ServerList) {

        # Get the thumbprint of the UM assigned certificate
        Write-Host -ForegroundColor Green  -BackgroundColor DarkGray  "Determining certificate used for UM services on $Identity"
        $CertThumbprint1 = Get-ExchangeCertificate -Server $Identity | Where {$_.Services -like '*UM*' -and $_.Status -eq "Valid"}
        $CertThumbprint= $CertThumbprint1.Thumbprint
        Write-Verbose $CertThumbprint1
        If( -not ( $CertThumbPrint) ) {
            Write-Error "Server $Identity does not contain an valid certificate assigned to UM services."
        }
        Else {
            Write-Host -ForegroundColor Green   "Using certificate $CertThumbPrint"

            # Determine web.config using installation path
            Write-Host -ForegroundColor Green   "Determining location of web.config"
            $Version= (Get-ExchangeServer -Identity $Server).AdminDisplayVersion.Major
            $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $Identity)
            $ExInstallPath = $reg.OpenSubKey("SOFTWARE\Microsoft\ExchangeServer\v$Version\Setup").GetValue("MsiInstallPath")
            $WebConfigFile= Join-Path $ExInstallPath "ClientAccess\Owa\web.config"
            $WebConfigFile= Join-Path "\\$Identity\" ( Join-Path ($WebConfigFile.subString(0,1) + '$') $WebConfigFile.subString(2))
            If( -not (Test-Path $WebConfigFile)) {
# Changed!!!
                Throw "Can't determine or access web.config at $WebConfigFile"
            }
        
            # Process web.config
            Write-Host -ForegroundColor Green   "Modifying $WebConfigFile"
            $wcf=[XML](Get-Content $WebConfigFile)
            Configure-WebConfigItem ([ref]$wcf) "IMCertificateThumbprint" $CertThumbprint
            Configure-WebConfigItem ([ref]$wcf) "IMServerName" $PoolFQDN
# Changed!!!
            if ($pscmdlet.ShouldProcess("Server $Identity", "Configuring WebConfig")) {
# Changed!!! (Moved)
                Copy-Item $WebConfigFile ($WebConfigFile + "_"+ ( Get-Date).toString("yyyMMddHHmmss")+ ".bak") -Force
                Write-Verbose "WebConfig: saving"
                $wcf.Save( $WebConfigFile)
                Write-Verbose "WebConfig: saved"

                #Restart OWA app pool
                Write-Host -ForegroundColor Green   "Restarting MSExchangeOWAAppPool on $Identity"
                Write-Host
                $AppPool= Get-WMIObject -ComputerName $Identity -Namespace "root\MicrosoftIISv2" -Class "IIsApplicationPool" -Authentication PacketPrivacy | Where { $_.Name -eq "W3SVC/APPPOOLS/MSExchangeOWAAppPool"}
                $AppPool.Recycle()
            } else {
                Write-Host -ForegroundColor Green  -BackgroundColor DarkGray  "Skipping $Identity"
                Write-Host
            }   
        }
    }
}
end {

# Changed!!!  (Moved)
    If( $AllCAS) {
        Get-ClientAccessServer | ForEach {
            if ($pscmdlet.ShouldProcess("Server $($_.Name)", "Configuring IM on CAS server")) {
                Write-Host -ForegroundColor Green   "Configuring IM on CAS server $($_.Name)"
                Set-OwaVirtualDirectory -Identity “$($_.Name)\OWA (Default Web Site)” –InstantMessagingEnabled $true –InstantMessagingType OCS
            } else {
                Write-Host -ForegroundColor Green  -BackgroundColor DarkGray  "Skipping $($_.Name)"
                Write-Host
            }
        }
    }

}
Реклама

Один ответ

  1. […] с ролью Mailbox, чтобы прописать имя пула и сертификат (либо скриптом), то теперь настройку можно сделать командлетами. Вот […]

Добавить комментарий

Заполните поля или щелкните по значку, чтобы оставить свой комментарий:

Логотип WordPress.com

Для комментария используется ваша учётная запись WordPress.com. Выход /  Изменить )

Фотография Twitter

Для комментария используется ваша учётная запись Twitter. Выход /  Изменить )

Фотография Facebook

Для комментария используется ваша учётная запись Facebook. Выход /  Изменить )

Connecting to %s

%d такие блоггеры, как: