Configure Exchange 2013 Virtual Directories

Configure Exchange 2013 Virtual Directories

When you’re working with more then 1 exchange servers then configuring exchange virtual directories is always a concern. You can either manually configure each virtual directory on each server or you use powershell cmdlets to configure the virtual directories. To ease your deployment, I’ve created a powershell script which will help you configure virtual directories URLs on your all exchange 2013 servers within minutes. You only have to provide 3 inputs for Internal, External URL and AutodiscvoerServiceInternalURI and rest this script will do for you.

#       Author: Riaz Javed Butt
#       Date: 03-June-2015
#       Description: This scirpt will help you configure your exchange 2013 organization URLs

#Get all exchange 2013 CAS Servers
$Exchange2013Servers = Get-ExchangeServer | Where {($_.AdminDisplayVersion -Like “Version 15*”) -And ($_.ServerRole -Like “*ClientAccess*”)} | Get-ClientAccessServer

#Get Internal & External URL

$CASInternalURL = Read-Host “Please enter your internal URL e.g.”
$CASExternalURL = Read-Host “Please enter your external URL e.g.”

#Get autodiscoverServiceURI

$AutoDServiceInternalURI = Read-host “Please enter your autodiscoverserviceinternalURI e.g.”
Write-Host “Thank you for providing Required URLs”

#Setting up AutodiscoverInternalServiceURI
Write-Host “Setting up Exchange AutodiscoverServiceInternalURI”
$Exchange2013Servers | Set-ClientAccessServer –AutodiscoverServiceInternalUri “$AutoDServiceInternalURI/autodiscover/autodiscover.xml”

#Setting up virtual Directories URLs
Write-Host “Setting up Virtual Directory Internal and External URLs”
$Exchange2013Servers | Get-OWAvirtualDirectory | Set-OWAvirtualdirectory –Internalurl “$CASInternalURL/OWA” –Externalurl “$CASExternalURL/OWA”
$Exchange2013Servers | Get-ECPVirtualdirectory | Set-ECPvirtualdirectory –Internalurl “$CASInternalURL/ECP” –Externalurl “$CASExternalURL/ECP”
$Exchange2013Servers | Get-WebServicesVirtualDirectory | Set-WebServicesvirtualdirectory –InternalURL “$CASInternalURL/ews/exchange.asmx” –ExternalURL “$CASExternalURL/ews/exchange.asmx”
$Exchange2013Servers | Get-OABvirtualdirectory | Set-OABvirtualdirectory –internalurl “$CASInternalURL/oab” –Externalurl “$CASExternalURL/oab”
$Exchange2013Servers | Get-ActiveSyncVirtualDirectory | Set-ActiveSyncVirtualDirectory -InternalUrl “$CASInternalURL/Microsoft-Server-ActiveSync” -ExternalUrl “$CASExternalURL/Microsoft-Server-ActiveSync”

#Verify URLs Configuration

$Exchange2013Servers | fl Identity,AutodiscoverServiceInternal*
$Exchange2013Servers | Get-OWAvirtualdirectory | fl identity,Externalurl,Internalurl
$Exchange2013Servers | Get-ECPvirtualdirectory | fl identity,Externalurl,Internalurl
$Exchange2013Servers | Get-Webservicesvirtualdirectory | fl identity,Externalurl,Internalurl
$Exchange2013Servers | Get-OABvirtualdirectory | fl identity,Externalurl,Internalurl
$Exchange2013Servers | Get-ActiveSyncVirtualDirectory | fl identity,Externalurl,Internalurl

#######You can also run Michael Van Horenbeeck Exchange MVP PowerShell Script to generate a HTML based report of your URLs configuration.
####### Please go to and downloaded the script get-virdirinfo.ps1 v1.6 and run as instructed

You can run this script go to Exchange Management Shell and run the script as shown below.


Once you run the script and provide the following 3 inputs then the script will configure everything for you on all exchange 2013 servers.

  • First input is InternalURL: In my case it was
  • Second input is ExternalURL: In my case it’s same as of internal URL
  • Third input is AutodiscoverServiceInternalURI: I’ve configured that as

Once the configure is completed this script will give you the output of all configured virtual directories along with new URLs as shown below.




You can download this script from TechNet Gallery.

To generate a HTML based report of Exchange 2013 virtual Directories URLs, Please run the powershell script of Michael Van Horeenbeeck that can be downloaded from


  • Andres Suarez

    This is a very well written yet very simple and effective Script. The exact example of what Scripting is designed for.

    Great work.