############################################################################### # This script handles OWA updates. ############################################################################### trap { Log ("Error patching OWA: " + $_) Exit } $WarningPreference = 'SilentlyContinue' $ErrorActionPreference = 'Stop' $ConfirmPreference = 'None' $script:logDir = "$env:SYSTEMDRIVE\ExchangeSetupLogs" # Log( $entry ) # Append a string to a well known text file with a time stamp # Params: # Args[0] - Entry to write to log # Returns: # void function Log { $entry = $Args[0] $line = "[{0}] {1}" -F $(get-date).ToString("HH:mm:ss"), $entry add-content -Path "$logDir\UpdateOwa.log" -Value $line } # Load the Exchange PS snap-in add-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.Admin Log "************************************************" Log ("* patch-owa.ps1: {0}" -F $(get-date)) # If CAS isn't installed on this server, exit without doing anything if ((Get-ExchangeServer $([Environment]::MachineName)).ServerRole -match "ClientAccess") { Log "Updating OWA on server $([Environment]::MachineName)" } else { Log "CAS role is not installed on server $([Environment]::MachineName)" Exit } # get the path to \owa on the filesystem Log "Finding OWA install path on the filesystem" $owapath = (get-itemproperty HKLM:\SOFTWARE\Microsoft\Exchange\Setup).MsiInstallPath + "ClientAccess\owa\" # figure out which version of OWA we are moving to if (! (test-path ($owapath + "bin\Microsoft.Exchange.Clients.owa.dll"))) { Log "Could not find '${owapath}bin\Microsoft.Exchange.Clients.owa.dll'. Aborting." Exit } $version = ([diagnostics.fileversioninfo]::getversioninfo($owapath + "bin\Microsoft.Exchange.Clients.owa.dll")).fileversion -replace '(\.?)0+(\d)','$1$2' Log "Updating OWA to version $version" # filesystem path to the new version directory $versionpath = $owapath + $version if (test-path $versionpath\*) { # if new version directory isn't empty, copy \Current\* into it Log "Copying files from '${owapath}Current' to '$versionpath'" copy-item -recurse -force ($owapath + "Current\*") $versionpath } else { # if the new version directory is empty, remove it Log "Deleting $versionpath because it is empty, then aborting." remove-item -recurse -force $versionpath Exit } # get all OWA vdirs on the server Log "Getting all Exchange 2007 OWA virtual directories" $paths = @(get-owavirtualdirectory -server $([Environment]::MachineName) | ? { $_.OwaVersion -eq "Exchange2007" } | % { $_.MetabasePath }) # if there are no Exchange 2007 OWA vdirs on the server, we should exit if (($paths.Count -eq 0) -or ($paths -eq $null)) { Log "There are no Exchange 2007 OWA virtual directories. Aborting." Exit } else { Log ("Found " + $paths.Count + " OWA virtual directories.") } # create IIS metabase entries for the new version directory and set properties Log "Updating OWA virtual directories" foreach ($path in $paths) { if (! [ADSI]::Exists($path)) { Log "Skipping metabase path '$path' because it does not exist. This may be because it is an orphaned virtual directory." continue } else { Log "Processing virtual directory with metabase path '$path'." } $owavdir = [ADSI]$path if (! $owavdir) { Log "Could not create DirectoryEntry object for path '$path'. Skipping this virtual directory." continue } if ([ADSI]::Exists("$path/$version")) { Log "Metabase entry '$path/$version' exists. Removing it." $owavdir.psbase.Children.remove([ADSI]("$path/$version")) } Log "Creating metabase entry $path/$version." $de = $owavdir.psbase.Children.add($version, "IIsWebDirectory") Log "Configuring metabase entry '$path/$version'." $de.psbase.Path.Insert(0, $versionpath) | out-null $de.psbase.InvokeSet("AuthFlags","1") $de.psbase.InvokeSet("DirBrowseFlags","1073741882") $de.psbase.InvokeSet("LogonMethod","3") $de.psbase.InvokeSet("AccessFlags","1") $de.psbase.InvokeSet("AppPoolId","MSExchangeOWAAppPool") $de.psbase.InvokeSet("HttpExpires","D, 0x278d00") Log "Saving changes to '$path/$version'" $de.psbase.CommitChanges() Log "Saving changes to '$path'" $owavdir.psbase.CommitChanges() $de.psbase.Close() $owavdir.psbase.Close() } # Remove the Exchange PS snap-in remove-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.Admin