This article describes how to reset and recreate virtual directories (including OWA and ECP) on on-premises Exchange Server 2019/2016/2013. Resetting of virtual directories can solve many Exchange Server problems related to the incorrect operation of OWA or ECP, such as: page errors (including HTTP 404, 500, ECP runtime), blank screen and Outlook connectivity issue, IIS permission problems, missing files, etc.
Virtual directories in Exchange Server used by client applications to access various web-based services. For example, Outlook Web App (OWA), Exchange Active Sync, Autodiscover, Exchange Control Panel (ECP), etc. Users may experience various problems when accessing Exchange services if these virtual directories are missing, corrupt, or misconfigured.
Recreate OWA and ECP Virtual Directories on Exchange Server
You can get a list of virtual directories on Exchange (%SystemRoot%\System32\Inetsrv\Inetmgr.exe). Open the IIS manager, and expand YourServer > Sites. There are two built-in IIS sites that are created during the Exchange installation:
- DefaultWebSite (TCP ports 80 and/or 443);
- ExchangeBackEnd (TCP ports 81 and/or 444).
There are multiple Exchange virtual directories on each of these IIS sites (depending on Exchange roles installed on the server).
- EcpVirtualDirectory (ecp);
- OwaVirtualDirectory (owa);
- MapiVirtualDirectory (mapi);
- ActiveSyncVirtualDirectory (Microsoft-Server-ActiveSync);
- AutodiscoverVirtualDirectory (Autodiscover);
- OABVirtualDirectory (OAB);
- PowerShellVirtualDirectory (PowerShell);
- WebServicesVirtualDirectory (EWS).
The most common problems are with the ECP and OWA virtual directories, so we will now look at how to recreate these directories using PowerShell.
- ECP — virtual directory used by administrators to manage Exchange through the web interface of the Exchange Admin Center.
- OWA (Outlook Web Access) is a virtual directory that implements a client web interface for accessing a user’s mailbox.
Run the Exchange Management Shell (EMS) as administrator.
Use the following PowerShell command to display a list of all the OWA directories in the Exchange organization:
Then list the ECP virtual directories:
We are going to repair the ecp (Default Web Site) and owa (Default Web Site) virtual directories on the server EX2016.
List the current settings of the OWA and ECP virtual directories (note the configured ExternalURL, InternalURL, and authentication settings):
Get-OwaVirtualDirectory "ex2016\owa (Default Web Site)"|select-object InternalUrl, ExternalUrl, BasicAuthentication,WindowsAuthentication,DigestAuthentication, FormsAuthentication
Get-EcpVirtualDirectory "ex2016\ecp (Default Web Site)"|select-object InternalUrl, ExternalUrl, BasicAuthentication,WindowsAuthentication,DigestAuthentication, FormsAuthentication
Note. Change ex2016 to the name of your Exchange Server.
Delete the OWA virtual directory on the server ex2016:
Remove-OwaVirtualDirectory “ex2016\owa (Default Web Site)”
Create a new OWA directory:
New-OwaVirtualDirectory -InternalUrl “https://mail.contoso.local/owa” -ExternalUrl “https://mail.contoso.local/owa”
Now delete and recreate the ECP virtual directory in a similar way:
Remove-EcpVirtualDirectory -Identity “ex2016\ecp (Default Web Site)”
New-EcpVirtualDirectory -InternalUrl “https://mail.contoso.local/ecp” -ExternalUrl “https://mail.contoso.local/ecp”
In some cases, it is also useful to recreate OWA and ECP on the Exchange Back End site:
Remove-OwaVirtualDirectory “ex2016\owa (Exchange back end)”
Remove-EcpVirtualDirectory -Identity “ex2016\ecp (Exchange Back End)”
New-OwaVirtualDirectory -InternalUrl “https://mail.contoso.local/owa” -ExternalUrl “https://mail.contoso.local/owa” -WebSiteName “Exchange Back End”
New-EcpVirtualDirectory -Server ServerName -ExternalURL “https://mail.contoso.local/ecp” -InternalURL “https://mail.contoso.local /ecp” -WebSiteName “Exchange Back End”
Reset OWA Virtual Directory from Exchange Control Panel
In some cases, to resolve an issue with the OWA virtual directory in Exchange IS, you can try to perform a reset directly from the ECP web interface. To do this:
- Sign in Exchange Control Panel (using the link https://yourexchange/ECP);
- Go to Server > Virtual directories;
- Select the owa (default Web Site) directory and click the Reset button;
- You will be prompted for a file name to save the current OWA virtual directory settings.
When you reset “owa (default Web Site)” virtual directory, the current settings will be lost. The current virtual directory will be deleted and then re-created with the default settings.
- Click Reset;
- Then restart IIS with the command;
- Manually set InternalUrl and ExternalUrl for OWA.
Rebuilding Other Exchange Virtual Directories using PowerShell
We have previously covered how to repair OWA and ECP virtual directories. These Exchange virtual directories most commonly cause problems. However, there are several service virtual directories in Exchange. Problems with them happen less often, but in some cases, you will also have to recreate them from scratch.
You can get info about other Exchange virtual directories by using the EMS cmdlets:
The following table lists the default IIS authentication methods that are enabled by default for various Exchange virtual directories:
IIS Default Authentication methods
Recreate Exchange ActiveSync virtual directory:
Remove-ActiveSyncVirtualDirectory -Identity "ex2016\Microsoft-Server-ActiveSync (Default Web Site)"
New-ActiveSyncVirtualDirectory -Server "ex2016" -InternalUrl "https://mail.contoso.local/Microsoft-Server-ActiveSync" -ExternalUrl "https://mail.contoso.local/Microsoft-Server-ActiveSync"
Recreate Autodiscover virtual directory:
Remove-AutodiscoverVirtualDirectory -Identity "ex2016\Autodiscover (Default Web Site)"
New-AutodiscoverVirtualDirectory -Server "ex2016" -BasicAuthentication $true -WindowsAuthentication $true
Set-ClientAccessServer -Identity "ex2016" -AutodiscoverServiceInternalUri https://autodiscover.contoso.local/Autodiscover/Autodiscover.xml
Recreate Exchange Web Services (EWS):
Remove-WebServicesVirtualDirectory -Identity "ex2016\EWS (Default Web Site)" -Confirm:$True
New-WebServicesVirtualDirectory -Server "ex2016" -InternalUrl "https://mail.contoso.local/EWS/Exchange.asmx" -ExternalUrl "https://mail.contoso.local/EWS/Exchange.asmx"
Recreate MAPI virtual directory:
Remove-MapiVirtualDirectory -Identity "ex2016\mapi (Default Web Site)"
New-MapiVirtualDirectory -Server "ex2016" -InternalUrl https://mail.contoso.local/mapi -ExternalUrl https://mail.contoso.local/mapi -IISAuthenticationMethods Ntlm, OAuth, Negotiate
Recreate Online Address Book (OAB) virtual directory:
Remove-OabVirtualDirectory -Identity "ex2016\OAB (Default Web Site)"
New-OabVirtualDirectory -Server "ex2016" -InternalUrl "https://mail.contoso.local/OAB" -ExternalUrl "https://mail.contoso.local/OAB"
Recreate PowerShell virtual directory:
Remove-PowerShellVirtualDirectory -Identity "ex2016\PowerShell (Default Web Site)"
New-PowerShellVirtualDirectory -Server "ex2016" -Name Powershell -InternalUrl https://mail.contoso.local/PowerShell -ExternalUrl https://mail.contoso.local/PowerShell -RequireSSL:$false
Restart IIS or reboot the Exchange Server host.
Now open your browser and sign-in to the Exchange Admin Center (EAC). Select Servers item in the left pane and click Virtual Directories in the top menu. In the Select Server field, select the name of the Exchange host on which you have recreated the virtual directories. Check that all the Exchange virtual directories that you re-created are now displayed in the EAC console.
New-OwaVirtualDirectory: An Error Occurred While Creating the IIS Virtual Directory
In some cases, you may receive an error when you recreate a virtual directory in Exchange by using the New-OwaVirtualDirectory or New-OwaVirtualDirectory cmdlets:
An error occurred while creating the IIS virtual directory `IIS://Exch2016/W3SVC/1/ROOT/ECP’
The AD configuration for virtual directory ‘owa’ already exists in ‘CN=xxx’ , please remove this AD configuration manually.
This error occurs because the IIS metabase contains a record of the virtual directory that was created, which prevents the New-EcpVirtualDirectory cmdlet from creating a new directory.
It is important to understand that Exchange virtual directories are stored in two locations:
- Active Directory
The Get-EcpVirtualDirectory cmdlet (or a similar cmdlet for different virtual directories) gets information from AD, and not from the IIS configuration.
The Remove-XXXVirtualDirectory cmdlet removes the Exchange virtual directory from AD.
Run the ADSI Edit tool and connect to your domain configuration. Go to the following directory configuration partition: CN=Configuration > CN=Services > CN= Microsoft Exchange > CN=YourExchangeName > CN=Administrative Groups > CN=Exchange Administrative Groups > CN=Servers > CN=YourExchangeServerName > CN=Protocols > CN=HTTP. Find the virtual directory you want to recreate in this partition.
If the directory is removed from IIS but remains in AD, you must first remove the directory from AD using the Remove-XXXVirtualDirectory cmdlet (where XXX is the name of the directory: ECP, OWA, etc.).
Hint. Do not use IIS Manager to manually delete virtual directories on your Exchange Server unless you are sure that the metadata for them is not stored in Active Directory.
If the directory is still in IIS but removed from the Active Directory configuration, you will get the following error when trying to recreate it using the New-XXXVirtualDirectory PowerShell cmdlet:
An error occurred while creating the IIS virtual directory ‘IIS:// ex2016/W3SVC/1/ROOT/owa’ on ex2016′. Cmdlet-InvalidOperationExceptio:
In this case, you must remove it from the IIS configuration:
- Install the Metabase Explorer tool from the IIS 6 Resource Kit;
- Open the IIS Metabase Explorer, and go to Exchange > LM > W3SVC > 1 > ROOT;
- Delete the required directory by right-clicking and selecting Delete.
Restart IIS with the command:
Now attempt to create the virtual directory again using the New-EcpVirtualDirectory, New-OwaVirtualDirectory, or New-WebApplication cmdlets.