Tame Those Pesky Exchange URLs

Now most people don’t build a new Exchange server everyday, every week or even every month. However, as an IT consultant I am constantly build, trashing and rebuilding labs with Exchange 2007, 2010 and 2013. Every time I build a new server I need to set the URLs to the environment that I am building. Not quite your typical situation for most people. I decided to create a script (yes, a script!) to help with this task. So what do we need to set in an Exchange environment? What virtual directories do Outlook, OWA and smartphones need in order to use Exchange properly?

  • Offline Address Book (OAB)
  • Web Services (EWS)
  • Active Sync (EAS)
  • Outlook Web Access (OWA)
  • AutoDiscoverServiceInternalUri – Setting on CAS defining AutoDiscover

So how do we set all of these in a programmatic manner? Well, let’s look at my simple script:

$FQDN = Read-Host 'Enter the URL you want to use for your Exchange URLs'
write-host $FQDN" will be used for the common name of all virtual directories."
start-sleep -seconds 10

# To be used if setting all CAS the same
# $cas = get-clientaccessserver

# To be used if setting only one CAS server up
$cas = Read-Host 'Enter the name of the CAS server you want to modify.'
write-host $cas" will be used for the common name of all virtual directories."
start-sleep -seconds 10

# Set various VD - ews, oab, autodiscover, ecp, powershell?, autodiscover, outlook anywhere, 

write-host "You picked "$FQDN" for the name in the environment."
write-host "Your FQDNS will be as follows for internal and external URLs:"
write-host "https://$FQDN/exchange.asmx"
write-host "https://$FQDN/owa"
write-host "https://$FQDN/Microsoft-Server-ActiveSync"
write-host "https://$FQDN/oab"
# Skip if pre-2010
write-host "https://$FQDN/ecp"
write-host "Is this OK?  Settings will apply in 5 seconds.  Hit any key to abort."
start-sleep -seconds 5

foreach ($line in $cas) {
# EWS setting
Set-WebServicesVirtualDirectory -Identity "$line\EWS (Default Web Site)" -internalurl https://$FQDN/ews/exchange.asmx -externalurl https://$FQDN/ews/exchange.asmx
# OWA setting
set-OWAVirtualDirectory -Identity "$line\owa (Default Web Site)" -InternalURL https://$FQDN/owa -externalurl https://$FQDN/owa
# ActiveSync setting
Set-ActiveSyncVirtualDirectory -Identity "$line\Microsoft-Server-ActiveSync (Default Web Site)" -InternalURL https://$FQDN/Microsoft-Server-ActiveSync -externalurl https://$FQDN/Microsoft-Server-ActiveSync
#OAB setting
Set-OabVirtualDirectory -Identity "$line\OAB (Default Web Site)" -InternalURL https://$FQDN/oab -externalurl https://$FQDN/oab
# Set Client Access Server Internal Uri
set-clientaccessserver $cas -AutoDiscoverServiceInternalUri https://$fqdn/autodiscover/autodiscover.xml
# For Exchange 2010 +
# ECP setting
Set-EcpVirtualDirectory -Identity "$line\ecp (Default Web Site)" -InternalURL https://$FQDN/ecp -externalurl https://$FQDN/ecp

Note the script is short and simple. You may have to make adjustments as I have not coded the script to determine if you are running Exchange 2007, 2010 pr 2013. Also note that you can make the change for one server or multiple servers, it is up to you.

Lastly, this script changes the URLs for internal and external settings. Make sure this is what you want to do. If you need to configure a separate namespace, setup a second variable for this like $fdqn2 and then plug that into either the internal or external URL, depending on what you want to do with it.

Download the script from here:
** Don’t forget to rename the file to .ps1.


One thought on “Tame Those Pesky Exchange URLs

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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s