<# .SYNOPSIS Sets redirection from root and forces SSL settings .DESCRIPTION Redirects / to /owa and forces SSL on recommended vdirs Configures rights on web.config file for OAB .PARAMETER URL Specifies the destination to redirect to .PARAMETER ForceSSL Whether the Exchange specific virtual directories are set to require SSL. Default is $True .NOTES Version : 1.0 - 04/26/2010 - initial version Rights Req'd : Local Server Admin Sch Task Req : No Exchange Ver : 2010 Author : Pat Richard, Exchange MVP Email : pat@innervation.com Blog : http://www.ucblogs.net/blogs/exchange Disclaimer : Don't blame me if this breaks your stuff. Info Stolen : .LINK http://www.ucblogs.net/blogs/exchange/archive/2010/04/28/Redirecting-the-root-web-site-to-_2F00_owa-and-forcing-SSL-in-Exchange-2010.aspx ADDED settings to reflect this site - http://briandesmond.com/blog/redirecting-owa-urls-in-exchange-2010/ .EXAMPLE .\Set-Exchange2010RedirectSSL.ps1 -url "https://mail.ehloworld.com/owa" .INPUTS None. You cannot pipe objects to this script. #> #Requires -Version 2.0 param( [Parameter(Mandatory = $false,valueFromPipeline=$true)][string] $ForceSSL, [Parameter(Mandatory = $false,valueFromPipeline=$false)][string] $SetupRegistryPath, [Parameter(Mandatory = $false,valueFromPipeline=$false)][string] $SetupEntries, [Parameter(Mandatory = $false,valueFromPipeline=$false)][string] $InstallPath, [Parameter(Mandatory = $false,valueFromPipeline=$false)][string] $PathToFile, [Parameter(Mandatory = $false,valueFromPipeline=$false)][string] $Post_Install ) #end param $defaultExchangeAdminGroup = "Exchange Administrative Group (FYDIBOHF23SPDLT)" $objPartitionPath = "LDAP://CN=Partitions," + ([ADSI]'LDAP://RootDSE').configurationNamingContext $objSchemaPath = "LDAP://" + ([ADSI]'LDAP://RootDSE').schemaNamingContext $objConfigurationPath = "LDAP://" + ([ADSI]'LDAP://RootDSE').configurationNamingContext $objDefaultPath = "LDAP://" + ([ADSI]'LDAP://RootDSE').defaultNamingContext $objHostName = [System.Net.Dns]::GetHostByName("localhost").HostName $objComputerName = $env:computername #Get OS Version $QueryOS = Gwmi Win32_OperatingSystem $QueryOS = $QueryOS.Version If ($QueryOS.contains("6.1")) { $OS = "Win2008R2" Write-Host -ForegroundColor Blue "- Running on $OS." Import-Module ServerManager if ((Get-WindowsFeature web-http-redirect).installed -eq $false){ Write-Host "`nInstalling web-http-redirect feature" -ForegroundColor green ServerManagerCMD -i web-http-redirect } } ElseIf ($QueryOS.contains("6.0")) { $OS = "Win2008" Write-Host -ForegroundColor Blue "- Running on $OS." Write-Host "`nInstalling web-http-redirect feature" -ForegroundColor green ServerManagerCMD -i web-http-redirect } function configureLogonDomain{ $objPartitionPath = "LDAP://CN=Partitions," + ([ADSI]'LDAP://RootDSE').configurationNamingContext $colPartition = [ADSI] $objPartitionPath foreach($index in $colPartition.children){ $objDNSName = [ADSI] $index.path if ($objDNSName.nCName -eq ([ADSI]'LDAP://RootDSE').defaultNamingContext){ $objNETBios = $objDNSName.nETBIOSName $objInternalDNSName = $objDNSName.dnsRoot } } $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://$objHostName/powershell/ -Authentication Kerberos Import-PSSession $Session Get-OwaVirtualDirectory -Server $objHostName | Set-owavirtualdirectory -LogonFormat UserName -DefaultDomain $objInternalDNSName Remove-PSSession $Session } function SearchAD ($strFilter,$ADcontext){ $root = New-Object System.DirectoryServices.DirectoryEntry $ADcontext $objSearcher = New-Object System.DirectoryServices.DirectorySearcher $objSearcher.SearchRoot = $root $objSearcher.PageSize = 1000 $objSearcher.Filter = "$strFilter" $objSearcher.SearchScope = "Subtree" # $objSearcher.PropertiesToLoad.Add("Path") $objSearcher.FindAll() } function GetExchangeInstallPath { # Get the root setup entires. $setupRegistryPath = "HKLM:\SOFTWARE\Microsoft\ExchangeServer\v14\Setup" $setupEntries = Get-ItemProperty $setupRegistryPath if($setupEntries -eq $null) { return $null } # Try to get the Install Path. $InstallPath = $setupEntries.MsiInstallPath return $InstallPath } # end GetExchangeInstallPath $colExternalOWA = SearchAD "(objectClass=msExchOWAVirtualDirectory)" $objConfigurationPath if($colExternalOWA.path -ne $null -and $colExternalOWA.count -eq $null){ $objExternalOWA = [ADSI]$colExternalOWA.path if($colExternalOWA.path.contains("CN=" + $objComputerName + ",")){ $url = $objExternalOWA.msExchExternalHostName.ToString() } } elseif($colExternalOWA.count -gt 1){ foreach($objOWA in $colExternalOWA){ $objOWADN = $objOWA.path if($objOWADN.contains("CN=" + $objComputerName + ",")){ $objExternalOWA = [ADSI]$objOWA.path $url = $objExternalOWA.msExchExternalHostName.ToString() } } } else{ write-host "External OWA URL Not found" } if ($url -ne $NULL) { # $yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", ` # "Deletes all the files in the folder." # $no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", ` # "Retains all the files in the folder." # $options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no) # $result = $host.ui.PromptForChoice("OWA Redirect", "This will configure a redirect for "+$url + " on this server: " + $objHostName, $options, 1) # switch ($result){ # 0 { $PathToFile = (GetExchangeInstallPath)+"ClientAccess\OAB\web.config" Set-Location "c:\Windows\System32\inetsrv" Write-Host "Backing up current IIS configuration" -ForegroundColor green $backup = "OWA Redirect Backup "+(get-date -format "MMddyyyy-hhmmss") .\appcmd.exe ADD Backup $backup Write-Host "`nConfiguring redirection to $url" -ForegroundColor green .\appcmd set config "Default Web Site" /section:httpRedirect /childonly:true /enabled:true /destination:"$url" .\appcmd set config "Default Web Site/Aspnet_Client" /section:httpRedirect /enabled:false .\appcmd set config "Default Web Site/Autodiscover" /section:httpRedirect /enabled:false .\appcmd set config "Default Web Site/EWS" /section:httpRedirect /enabled:false .\appcmd set config "Default Web Site/ECP" /section:httpRedirect /enabled:false .\appcmd set config "Default Web Site/Microsoft-Server-ActiveSync" /section:httpRedirect /enabled:false .\appcmd set config "Default web site/OAB" /section:httpRedirect /enabled:false .\appcmd set config "Default web site/PowerShell" /section:httpRedirect /enabled:false .\appcmd set config "Default Web Site/Rpc" /section:httpRedirect /enabled:false Write-Host "`nConfiguring redirection to $url for Error '403'" -ForegroundColor green .\appcmd set config "Default Web Site/owa" /section:httpErrors "/[statusCode='403'].responseMode:Redirect" .\appcmd set config "Default Web Site/owa" /section:httpErrors "/[statusCode='403'].path:$url" if ($ForceSSL -ne $false){ Write-Host "`nSetting SSL configuration" -ForegroundColor green .\appcmd set config "Default Web Site" /section:access /sslFlags:"" /commit:apphost .\appcmd set config "Default Web Site/Autodiscover" /section:access /sslFlags:"Ssl,Ssl128" /commit:apphost .\appcmd set config "Default Web Site/EWS" /section:access /sslFlags:"Ssl,Ssl128" /commit:apphost .\appcmd set config "Default Web Site/ECP" /section:access /sslFlags:"Ssl,Ssl128" /commit:apphost .\appcmd set config "Default Web Site/Exchange" /section:access /sslFlags:"Ssl,Ssl128" /commit:apphost .\appcmd set config "Default Web Site/Exchweb" /section:access /sslFlags:"Ssl,Ssl128" /commit:apphost .\appcmd set config "Default Web Site/Microsoft-Server-ActiveSync" /section:access /sslFlags:"Ssl,Ssl128" /commit:apphost .\appcmd set config "Default Web Site/OWA" /section:access /sslFlags:"Ssl,Ssl128" /commit:apphost .\appcmd set config "Default web site/PowerShell" /section:access /sslFlags:"" /commit:apphost .\appcmd set config "Default web site/OAB" /section:access /sslFlags:"" /commit:apphost .\appcmd set config "Default Web Site/Public" /section:access /sslFlags:"Ssl,Ssl128" /commit:apphost .\appcmd set config "Default Web Site/Rpc" /section:access /sslFlags:Ssl /commit:apphost .\appcmd set config "Default Web Site/RpcWithCert" /section:access /sslFlags:"Ssl,Ssl128,SslNegotiateCert,SslRequireCert" /commit:apphost } if (Test-Path($PathToFile)){ icacls $PathToFile /grant:R 'NT Authority\Authenticated Users:R' } Write-Host "`nSetting Default Logon Domain" -ForegroundColor green configureLogonDomain Write-Host "`nRestarting IIS for configuration to take effect" -ForegroundColor green iisreset # } # 1 {"You selected No." # } # } } else { Write-Host "`nCould not find this server listed with an External URL for OWA. This script must be run from the Client Access server where IIS is running OWA." -ForegroundColor Red }