Exchange Server 2007, 2010, 2013, 2016 URL configuration

I had previously written a script to handle this and found it a bit lacking. This is a brand new script written from scratch and it will handle Exchange 2007, 2010, 2013 and 2016. As of version 1.1, it will only run locally. I will add a remote capability for same level and mixed level environments in the next version. Will need to do some testing so it might not be out for another week or two.

The Script

Notice that because this script runs against multiple versions of Exchange. I attempt to cover the three major revisions of Exchange – Exchange 2007, Exchange 2010-2013 (pre MAPI), Exchange 2013/2016. The last category may be split depending.

<#  
.SYNOPSIS
   	Configured the Exchange Virtual Directory URLs for client access.

.DESCRIPTION  
    This script will configure Exchange URLs based on the version of the Exchange Server the script is run against.

.NOTES  
    Version      		: 1.1
    Change Log			: 1.1 - Tweaks to the look, operation and correct some syntax errors after testing on 2007, 2010, 2013, 2016
                        : 1.0 - Base script
    Wish list			: 

    Rights Required		: Local admin on server
    Sched Task Req'd	: No
    Exchange Version    : 2007-2016
    Author       		: Damian Scoles
    Dedicated Blog		: https://justaucguy.wordpress.com/
    Disclaimer   		: You are on your own.  This was not written by, support by, or endorsed by Microsoft.
    Info Stolen from 	: 

.LINK  
    [TBD]

Example
	.\Set-ExchangeURLs1.0.ps1

.INPUTS
	None. You cannot pipe objects to this script.

.Notes
    Requires - Version 2.0+
#>

# Clear variables
    $global:internalurl = $null
    $global:externalurl = $null

function Notice {
    cls
    write-host "For this first part, you need to chose the URLs to be used by OWA, Smart Phones, Outlook, etc." -ForegroundColor cyan
    start-sleep 4
}

function Notice2 {
    cls
    write-host "For the second part, you will assign names to various virtual directories." -ForegroundColor cyan
    start-sleep 6
}

Function GetURLs {
cls
Clear-Host
Pushd
[string] $menu = @'

	*************************************
	Exchange URLs - Internal and External
	*************************************

	Please select an option from the list below.

	1) Set Internal URL
	2) Set External URL
	3) Set Internal & External URLs
    
	99) Exit

	Select an option.. [1-99]?
'@

function InternalURL {
    $global:internal = Read-Host 'Enter the URL you want to use for your Exchange internal URLs.'
}

function ExternalURL {
    $global:external = Read-Host 'Enter the URL you want to use for your Exchange external URLs.'
}

function BothURL {
    $global:internal = Read-Host 'Enter the URL you want to use for your Exchange internal and external URLs.'
    $global:external = $global:internal
}



Do {	
	if ($opt -ne "None") {Write-Host "Last command: "$opt -foregroundcolor Yellow}
    $opt = Read-Host $menu
    switch ($opt)    {
    1 { # Gather the FQDN for internal URLs
        InternalURL
    }
    2 { # Gather the FQDN for external URLs
        ExternalURL
    }
    3 { # Gather the FQDN for both internal and external URLs
        BOTHUrl
    }

    99 {#	Exit
            if ($global:internal -ne $null) {
                write-host " ";write-host "The internal URL you have chosen is: " -nonewline -foregroundcolor white;write-host "$global:internal" -foregroundcolor yellow;write-host " "
            } else {
                write-host " ";write-host "You have not set an internal URL.";write-host " "
            }
            if ($global:external -ne $null) {
                write-host "The external URL you have chosen is: " -nonewline -foregroundcolor white;write-host "$global:external" -foregroundcolor yellow;write-host " "
            } else {
                write-host "You have not set an external URL.";write-host " "
            }
		}
	default {Write-Host "You haven't selected any of the available options. "}
	}
} while ($opt -ne 99)

}

$error.clear()

function VersionCheck {
    $ver = GCM exsetup |%{$_.Fileversioninfo} 
    $FVN= $ver.fileversion

#  Reserved for future Exchange 2016 Configurations
#    if (($fvn -gt "15.0.775.38") -and ($fvn -lt "15.1")) {
#        write-host "Exchange 2013 SP1+ but not 2016"
#    }

    if ($FVN -gt "15.0.775.38") {
        $global:state = "MAPI"
    }
    if (($FVN -like "14") -or ($FVN -like "15")) {
	    if ($FVN -lt "15.0.847.32") {
	        $global:state = "NOMAPI"
	    }
    }
    if ($FVN -lt "14.0.000.00") {
        $global:state = "2007"
    }
}


# Call all functions
Notice
GetURLs
$global:srvname = $env:computername
VersionCheck
Notice2
 
# Check

if ($state -eq "2007") {
    Clear-Host
    Pushd
    $server = $global:srvname

    [string] $menu = @'

	****************************************
	 Exchange Server 2007 URL Configuration
	****************************************
	
	Please select an option from the list below.
	
	1) Configure all URLS [OWA, OAB, WebServices, AutoDiscover URI, ActiveSync]
	2) Configure OWA URL
	3) Configure OAB URL
	4) Configure WebServices (EWS) URL
	5) Configure ActiveSync URL
	6) Configure AutoDiscover URI
	7) Configure Outlook Anywhere

	99) Exit

	Select an option.. [1-99]?
'@

function AllUrls {
    Set-WebServicesVirtualDirectory -Identity "$server\EWS (Default Web Site)" -internalurl https://$global:internal/ews/exchange.asmx -externalurl https://$global:external/ews/exchange.asmx
    set-OWAVirtualDirectory -Identity "$server\owa (Default Web Site)" -InternalURL https://$global:internal/owa -externalurl https://$global:external/owa
    Set-ActiveSyncVirtualDirectory -Identity "$server\Microsoft-Server-ActiveSync (Default Web Site)" -InternalURL https://$global:internal/Microsoft-Server-ActiveSync -externalurl https://$global:external/Microsoft-Server-ActiveSync
    Set-OabVirtualDirectory -Identity "$server\OAB (Default Web Site)" -InternalURL https://$global:internal/oab -externalurl https://$global:external/oab
    set-clientaccessserver $server -AutoDiscoverServiceInternalUri https://$global:external/autodiscover/autodiscover.xml
}

function OWAUrl {
     set-OWAVirtualDirectory -Identity "$server\owa (Default Web Site)" -InternalURL https://$global:internal/owa -externalurl https://$global:external/owa
}

function OABUrl {
    Set-OabVirtualDirectory -Identity "$server\OAB (Default Web Site)" -InternalURL https://$global:internal/oab -externalurl https://$global:external/oab
}

function EWSUrl {
    Set-WebServicesVirtualDirectory -Identity "$server\EWS (Default Web Site)" -internalurl https://$global:internal/ews/exchange.asmx -externalurl https://$global:external/ews/exchange.asmx
}

function EASUrl {
    Set-ActiveSyncVirtualDirectory -Identity "$server\Microsoft-Server-ActiveSync (Default Web Site)" -InternalURL https://$global:internal/Microsoft-Server-ActiveSync -externalurl https://$global:external/Microsoft-Server-ActiveSync
}
function URI {
    set-clientaccessserver $server -AutoDiscoverServiceInternalUri https://$global:external/autodiscover/autodiscover.xml
}

function OutlookAnywhere {
    CLS
    $OAAuth = read-host "What Outlook Anywhere Authentication do you want to configure - (1) NTLM or (2) Basic"
    if ($oaauth -eq "1") {$auth ="NTLM" }
    if ($oaauth -eq "2") {$auth ="Basic" }
    $SSLOffloading = read-host "Turn on SSL Offloading - (1) True or (2) False"
    if ($SSLOffloading -eq "1") {$SSL = $true }
    if ($SSLOffloading -eq "2") {$SSL = $false }
    set-outlookanywhere -Identity "$server\rpc (Default Web Site)" -ClientAuthenticationMethod $auth -IISAuthenticationMethods Basic,NTLM -ExternalHostname $global:external -SSLOffloading $ssl
}

Do { 
    if ($opt -ne "None") {Write-Host "Last command: "$opt -foregroundcolor Yellow}
    $opt = Read-Host $menu
    switch ($opt)    {
        1 { # All URLs
            AllUrls
        }
        2 { # Outlook Web Access URL
            OWAUrl
        }
        3 { # Offline Address Book URL
            OABUrl
        }
        4 { # Web Services URL
            EWSUrl
        }    
        5 { # Exchange ActiveSync URL
            EASUrl
        }
        6 { # AutoDiscover URI Configuration
        }
        7 { # Configure Outlook Anywhere
            OutlookAnywhere
        }

        99 { # Exit

        }
    }

} while ($opt -ne 99)


}

if ($state -eq "NOMAPI") {
    Clear-Host
    Pushd
    $server = $global:srvname

    [string] $menu = @'

	******************************************************************
	 Exchange Server 2010 to Pre Exchange 2013 SP1 URL Configuration
	******************************************************************
	
	Please select an option from the list below.
	
	1) Configure all URLS [OWA, OAB, WebServices, AutoDiscover URI, ActiveSync, ECP, PowerShell]
	2) Configure OWA URL
	3) Configure OAB URL
	4) Configure WebServices (EWS) URL
	5) Configure ActiveSync URL
	6) Configure AutoDiscover URI
	7) Configure ECP URL (*)
	8) Configure Outlook Anywhere
	9) Configure PowerShell URL

	99) Exit

	Select an option.. [1-99]?
'@

function AllUrls {
    Set-WebServicesVirtualDirectory -Identity "$server\EWS (Default Web Site)" -internalurl https://$global:internal/ews/exchange.asmx -externalurl https://$global:external/ews/exchange.asmx
    set-OWAVirtualDirectory -Identity "$server\owa (Default Web Site)" -InternalURL https://$global:internal/owa -externalurl https://$global:external/owa
    Set-ActiveSyncVirtualDirectory -Identity "$server\Microsoft-Server-ActiveSync (Default Web Site)" -InternalURL https://$global:internal/Microsoft-Server-ActiveSync -externalurl https://$global:external/Microsoft-Server-ActiveSync
    Set-OabVirtualDirectory -Identity "$server\OAB (Default Web Site)" -InternalURL https://$global:internal/oab -externalurl https://$global:external/oab
    set-clientaccessserver $server -AutoDiscoverServiceInternalUri https://$global:external/autodiscover/autodiscover.xml
    Set-EcpVirtualDirectory -Identity "$server\ecp (Default Web Site)" -InternalURL https://$global:internal/ecp -externalurl https://$global:external/ecp
    Set-MAPIVirtualDirectory -Identity "$server\MAPI (Default Web Site)" -InternalURL https://$global:internal/MAPI -externalurl https://$global:external/MAPI
    Set-PowerShellVirtualDirectory -Identity "$server\PowerShell (Default Web Site)" -InternalURL https://$global:internal/Powershell -externalurl https://$global:external/PowerShell
}

function OWAUrl {
     set-OWAVirtualDirectory -Identity "$server\owa (Default Web Site)" -InternalURL https://$global:internal/owa -externalurl https://$global:external/owa
}

function OABUrl {
    Set-OabVirtualDirectory -Identity "$server\OAB (Default Web Site)" -InternalURL https://$global:internal/oab -externalurl https://$global:external/oab
}

function EWSUrl {
    Set-WebServicesVirtualDirectory -Identity "$server\EWS (Default Web Site)" -internalurl https://$global:internal/ews/exchange.asmx -externalurl https://$global:external/ews/exchange.asmx
}

function EASUrl {
    Set-ActiveSyncVirtualDirectory -Identity "$server\Microsoft-Server-ActiveSync (Default Web Site)" -InternalURL https://$global:internal/Microsoft-Server-ActiveSync -externalurl https://$global:external/Microsoft-Server-ActiveSync
}
function URI {
    set-clientaccessserver $server -AutoDiscoverServiceInternalUri https://$global:external/autodiscover/autodiscover.xml
}
function OutlookAnywhere {
    CLS
    $OAAuth = read-host "What Outlook Anywhere Authentication do you want to configure - (1) NTLM or (2) Basic"
    if ($oaauth -eq "1") {$auth ="NTLM" }
    if ($oaauth -eq "2") {$auth ="Basic" }
    $RequireSSLe = read-host "Require SSL Encryption for External Clients - (1) Yes or (2) No"
    $RequireSSLi = read-host "Require SSL Encryption for Internal Clients - (1) Yes or (2) No"
    if ($RequireSSLe -eq "1") { $extSSL = $true }
    if ($RequireSSLe -eq "2") { $extSSL = $false }
    if ($RequireSSLi -eq "1") { $intSSL = $true }
    if ($RequireSSLi -eq "2") { $intSSL = $false }
    $SSLOffloading = read-host "Turn on SSL Offloading - (1) True or (2) False"
    if ($SSLOffloading -eq "1") {$SSL = $true }
    if ($SSLOffloading -eq "2") {$SSL = $false }
    set-outlookanywhere -Identity "$server\rpc (Default Web Site)" -ExternalClientAuthenticationMethod $auth -InternalClientAuthenticationMethod $auth -IISAuthenticationMethods Basic,NTLM -ExternalHostname $global:external -InternalHostname $global:internal -ExternalClientsRequireSsl $extSSL -InternalClientsRequireSsl $intSSL
}

Do { 
    if ($opt -ne "None") {Write-Host "Last command: "$opt -foregroundcolor Yellow}
    $opt = Read-Host $menu
    switch ($opt)    {
        1 { # All URLs
            AllUrls
         }
        2 { # Outlook Web Access URL
            OWAUrl
        }
        3 { # Offline Address Book URL
            OABUrl
        }
        4 { # Web Services URL
            EWSUrl
        }    
        5 { # Exchange ActiveSync URL
            EASUrl
        }
        6 { # AutoDiscover URI Configuration
            URI
        }
        7 { # Exchange Control Panel URL
            ECPUrl
        }
        8 { # Configure Outlook Anywhere
            OutlookAnywhere
        }
        10 { # PowerShell URL
            PowerShellUrl
        }

        99 {#	Exit

        }
    }

} while ($opt -ne 99)


}

if ($state -eq "MAPI") {
    Clear-Host
    Pushd
    $server = $global:srvname

[string] $menu = @'

    *********************************************
     Exchange Server 2013 SP1+ URL Configuration
    *********************************************
	
    Please select an option from the list below.
	
    1) Configure all URLS [OWA, OAB, WebServices, AutoDiscover URI, ActiveSync, ECP, MAPI, PowerShell]
    2) Configure OWA URL
    3) Configure OAB URL
    4) Configure WebServices (EWS) URL
    5) Configure ActiveSync URL
    6) Configure AutoDiscover URI
    7) Configure ECP URL (*)
    8) Configure MAPI URL (**)
    9) Configure Outlook Anywhere
    10) Configure PowerShell URL

    99) Exit

    Select an option.. [1-99]?
'@

function AllUrls {
    Set-WebServicesVirtualDirectory -Identity "$server\EWS (Default Web Site)" -internalurl https://$global:internal/ews/exchange.asmx -externalurl https://$global:external/ews/exchange.asmx
    set-OWAVirtualDirectory -Identity "$server\owa (Default Web Site)" -InternalURL https://$global:internal/owa -externalurl https://$global:external/owa
    Set-ActiveSyncVirtualDirectory -Identity "$server\Microsoft-Server-ActiveSync (Default Web Site)" -InternalURL https://$global:internal/Microsoft-Server-ActiveSync -externalurl https://$global:external/Microsoft-Server-ActiveSync
    Set-OabVirtualDirectory -Identity "$server\OAB (Default Web Site)" -InternalURL https://$global:internal/oab -externalurl https://$global:external/oab
    set-clientaccessserver $server -AutoDiscoverServiceInternalUri https://$global:external/autodiscover/autodiscover.xml
    Set-EcpVirtualDirectory -Identity "$server\ecp (Default Web Site)" -InternalURL https://$global:internal/ecp -externalurl https://$global:external/ecp
    Set-MAPIVirtualDirectory -Identity "$server\MAPI (Default Web Site)" -InternalURL https://$global:internal/MAPI -externalurl https://$global:external/MAPI
    Set-PowerShellVirtualDirectory -Identity "$server\PowerShell (Default Web Site)" -InternalURL https://$global:internal/Powershell -externalurl https://$global:external/PowerShell
}

function OWAUrl {
     set-OWAVirtualDirectory -Identity "$server\owa (Default Web Site)" -InternalURL https://$global:internal/owa -externalurl https://$global:external/owa
}

function OABUrl {
    Set-OabVirtualDirectory -Identity "$server\OAB (Default Web Site)" -InternalURL https://$global:internal/oab -externalurl https://$global:external/oab
}

function EWSUrl {
    Set-WebServicesVirtualDirectory -Identity "$server\EWS (Default Web Site)" -internalurl https://$global:internal/ews/exchange.asmx -externalurl https://$global:external/ews/exchange.asmx
}

function EASUrl {
    Set-ActiveSyncVirtualDirectory -Identity "$server\Microsoft-Server-ActiveSync (Default Web Site)" -InternalURL https://$global:internal/Microsoft-Server-ActiveSync -externalurl https://$global:external/Microsoft-Server-ActiveSync
}
function URI {
    set-clientaccessserver $server -AutoDiscoverServiceInternalUri https://$global:external/autodiscover/autodiscover.xml
}
function ECPUrl {
    Set-EcpVirtualDirectory -Identity "$server\ecp (Default Web Site)" -InternalURL https://$global:internal/ecp -externalurl https://$global:external/ecp
}
function Mapiurl {
    Set-MAPIVirtualDirectory -Identity "$server\MAPI (Default Web Site)" -InternalURL https://$global:internal/MAPI -externalurl https://$global:external/MAPI
}
function OutlookAnywhere {
    CLS
    $OAAuth = read-host "What Outlook Anywhere Authentication do you want to configure - (1) NTLM or (2) Basic"
    if ($oaauth -eq "1") {$auth ="NTLM" }
    if ($oaauth -eq "2") {$auth ="Basic" }
    $RequireSSLe = read-host "Require SSL Encryption for External Clients - (1) Yes or (2) No"
    $RequireSSLi = read-host "Require SSL Encryption for Internal Clients - (1) Yes or (2) No"
    if ($RequireSSLe -eq "1") { $extSSL = $true }
    if ($RequireSSLe -eq "2") { $extSSL = $false }
    if ($RequireSSLi -eq "1") { $intSSL = $true }
    if ($RequireSSLi -eq "2") { $intSSL = $false }
    $SSLOffloading = read-host "Turn on SSL Offloading - (1) True or (2) False"
    if ($SSLOffloading -eq "1") {$SSL = $true }
    if ($SSLOffloading -eq "2") {$SSL = $false }
    set-outlookanywhere -Identity "$server\rpc (Default Web Site)" -ExternalClientAuthenticationMethod $auth -InternalClientAuthenticationMethod $auth -IISAuthenticationMethods Basic,NTLM -ExternalHostname $global:external -InternalHostname $global:internal -ExternalClientsRequireSsl $extSSL -InternalClientsRequireSsl $intSSL
}
function Powershellurl {
    Set-PowerShellVirtualDirectory -Identity "$server\PowerShell (Default Web Site)" -InternalURL https://$global:internal/Powershell -externalurl https://$global:external/PowerShell
}

Do { 
    if ($opt -ne "None") {Write-Host "Last command: "$opt -foregroundcolor Yellow}
    $opt = Read-Host $menu

    switch ($opt)    {
        1 { # All URLs
            AllUrls
         }
        2 { # Outlook Web Access URL
            OWAUrl
        }
        3 { # Offline Address Book URL
            OABUrl
        }
        4 { # Web Services URL
            EWSUrl
        }    
        5 { # Exchange ActiveSync URL
            EASUrl
        }
        6 { # AutoDiscover URI Configuration
            URI
        }
        7 { # Exchange Control Panel URL
            ECPUrl
        }
        8 { # MAPI over HTTP URL
            MAPIUrl
        }
        9 { # Configure Outlook Anywhere
            OutlookAnywhere
        }
        10 { # PowerShell URL
            PowerShellUrl
        }
        99 {#	Exit

        }
    }

} while ($opt -ne 99)


}

cls
write-host " "
write-host "Confirm Virtual directory settings? (1) Yes or (2) No? "  -nonewline -foregroundcolor yellow
$Answer = read-host 
if ($answer -eq "1") {
    if ($state -eq "2007") {
    get-WebServicesVirtualDirectory -server $global:srvname |ft *lurl*
    get-OWAVirtualDirectory -server $global:srvname |ft *lurl*
    get-ActiveSyncVirtualDirectory -server $global:srvname |ft *lurl*
    get-OabVirtualDirectory -server $global:srvname |ft *lurl*
    get-clientaccessserver $global:srvname |ft *luri*
    get-outlookanywhere  -server $global:srvname |ft ExternalHostname,ClientAuthenticationMethod,IISAuthenticationMethods,SSLOffloading
    }
    if ($state -eq "NOMAPI") {
    get-WebServicesVirtualDirectory -server $global:srvname |ft *lurl*
    get-OWAVirtualDirectory -server $global:srvname |ft *lurl*
    get-ActiveSyncVirtualDirectory -server $global:srvname |ft *lurl*
    get-OabVirtualDirectory -server $global:srvname |ft *lurl*
    get-clientaccessserver $global:srvname |ft *uri*
    get-EcpVirtualDirectory -server $global:srvname |ft *lurl*
    get-PowerShellVirtualDirectory -server $global:srvname |ft *lurl*
    get-outlookanywhere  -server $global:srvname |ft ExternalHostname, InternalHostname,ExternalClientAuthenticationMethod,InternalClientAuthenticationMethod,IISAuthenticationMethods,ExternalClientsRequireSsl,InternalClientsRequireSsl,SSLOffloading
    }
    if ($state -eq "MAPI") {
    get-WebServicesVirtualDirectory -server $global:srvname |ft *lurl*
    get-OWAVirtualDirectory -server $global:srvname |ft *lurl*
    get-ActiveSyncVirtualDirectory -server $global:srvname |ft *lurl*
    get-OabVirtualDirectory -server $global:srvname |ft *lurl*
    get-clientaccessserver $global:srvname |ft *uri*
    get-EcpVirtualDirectory -server $global:srvname |ft *lurl*
    get-MAPIVirtualDirectory -server $global:srvname |ft *lurl*
    get-PowerShellVirtualDirectory -server $global:srvname |ft *lurl*
    get-outlookanywhere  -server $global:srvname |ft ExternalHostname, InternalHostname,ExternalClientAuthenticationMethod,InternalClientAuthenticationMethod,IISAuthenticationMethods,ExternalClientsRequireSsl,InternalClientsRequireSsl,SSLOffloading
    }
}

Each set of code is different and purposely so because Exchange 2007 does not have certain features that 2010 does and 2013 has features that 2010 does not. The script will detect which version of Exchange is on the local server and use the appropriate menu to drive the configuration.

Operation

When the script is started it starts with the first step and an explanation of what is to be accomplished:

URL-01

From this menu Internal and External URL options can be configured or the two URLs can be set the same:

URL-02

Then another notice about the next step:

URL-03

From this menu all URLs can be configured, or individual ones, as well as Outlook Anywhere as well as the AutoDiscover URI.

URL-04

Once this step completes, you can choose to verify the settings or exit the script:

URL-05

Other Menus

There are two other menus that appear if you use a different version of Exchange. The reason the above is for Exchange 2013 SP1+ is because this is when MAPI over HTTP was added to Exchange.

Exchange 2007

Exchange2007Menu

Exchange 2010

Exchange2010-menu

Download
Download HERE!

Advertisements

2 thoughts on “Exchange Server 2007, 2010, 2013, 2016 URL configuration

    • No, its not required. It just makes it more uniform when connecting to an Exchange server. Also, if the FQDN is load-balanced, this will allow you to connect to PowerShell via the FQDN and also have a SSL connection match the certificate name on the server.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s