This article describes how to recreate virtual directories (including OWA and ECP) on Exchange Server 2019/2016/2013. The repairing of these virtual directories helps to reset all settings, recreate them from the scratch and can solve many Exchange problems related to the incorrect operation of OWA or ECP: various page errors, blank screen issues, permission problems, missing files, Outlook connectivity issues, ECP runtime errors, HTTP 500 error, etc.
Let us remind you, that the virtual directories are required to access Exchange from web-based applications (such as Outlook Web App (OWA), Exchange Active Sync, Autodiscover). You can manage Exchange virtual directories in 3 ways: Exchange Admin Center (EAC), Microsoft Exchange Management PowerShell (EMS), IIS Manager mmc console (%SystemRoot%\System32\Inetsrv\Inetmgr.exe). In Exchange 2016/2013 Mailbox and Client Access, roles are merged into one role (separate CAS role was removed). Therefore, on the Mailbox server virtual directories are located in 2 different sites:
- On a DefaultWebSite site (listening TCP ports 80, 443);
- On an ExchangeBackEnd site (listening TCP ports 81, 444).
Recreate OWA and ECP Virtual Directories on Exchange
OWA and ECP virtual directories in the IIS Manager console look like this:
Hint. Complete list of IIS virtual directories in Exchange Server:
-
EcpVirtualDirectory (ecp);
-
OwaVirtualDirectory (owa);
-
MapiVirtualDirectory (mapi);
-
ActiveSyncVirtualDirectory (Microsoft-Server-ActiveSync);
-
AutodiscoverVirtualDirectory (Autodiscover);
-
OABVirtualDirectory (OAB);
-
PowerShellVirtualDirectory (PowerShell);
-
WebServicesVirtualDirectory (EWS).
You need to get the full name of the virtual directory on which the problems are observed. To do this, start the Exchange Management Shell console.
Hint. You can load the Microsoft Exchange Management PowerShell Snap-in into the current PowerShell session without starting EMS:
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn
Display a list of all OWA folders in the Exchange organization using the following PowerShell command:
Get-OwaVirtualDirectory
In our example, the name of the OWA virtual directory — owa (Default Web Site).
Note. Check our article on how to create CSR (Certificate Signing Request) for IIS on Windows.
The same for ECP virtual directory:
Get-ECPVirtualDirectory
We are interested in the directory ecp (Default Web Site) on the server named EX2016.
Display and note the current settings of the OWA and ECP virtual directories (ExternalURL, InternalURL, 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 named 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-WebApplication -Site "Exchange Back End" -Name owa remove-WebApplication -Site "Exchange Back End" -Name ecp New-WebApplication -Site "Exchange Back End" -Name owa -PhysicalPath "C:\Program Files\Microsoft\Exchange Server\V15\ClientAccess\owa" -ApplicationPool MSExchangeOWAAppPool New-WebApplication -Site "Exchange Back End" -Name ecp -PhysicalPath "C:\Program Files\Microsoft\Exchange Server\V15\ClientAccess\ecp" -ApplicationPool MSExchangeECPAppPool
Rebuilding Other Exchange Virtual Directories using PowerShell
We have previously covered how to repair OWA and ECP virtual directories. These Exchange virtual directories cause problems most often. 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:
Get-AutodiscoverVirtualDirectory Get-OABVirtualDirectory Get-MapiVirtualDirectory Get-ActiveSyncVirtualDirectory Get-PowerShellVirtualDirectory Get-WebServicesVirtualDirectory
The following cmdlets are used to remove these Exchange virtual directories:
Remove-ActiveSyncVirtualDirectory -Identity "ex2016\Microsoft-Server-ActiveSync (Default Web Site)" Remove-OabVirtualDirectory -Identity "ex2016\OAB (Default Web Site)" Remove-MapiVirtualDirectory -Identity "ex2016\mapi (Default Web Site)" Remove-AutodiscoverVirtualDirectory -Identity "ex2016\Autodiscover (Default Web Site)" Remove-PowerShellVirtualDirectory -Identity "ex2016\PowerShell (Default Web Site)" Remove-WebServicesVirtualDirectory -Identity "ex2016\EWS (Default Web Site)" -Confirm:$True
The following table lists the default IIS authentication methods that are enabled by default for various Exchange virtual directories:
Virtual directory | IIS Default Authentication methods |
OWA | Anonymous authentication
Windows authentication |
ECP | |
Autodiscover | |
EWS | |
MAPI
owa\Calender |
Anonymous authentication |
Microsoft-Server-ActiveSync | Basic authentication |
OAB | Windows authentication |
PowerShell | |
Rpc |
To create these Exchange virtual directories, use:
New-ActiveSyncVirtualDirectory -Server "ex2016" -InternalUrl "https://mail.contoso.local/Microsoft-Server-ActiveSync" -ExternalUrl "https://mail.contoso.local/Microsoft-Server-ActiveSync" New-AutodiscoverVirtualDirectory -Server "ex2016" -BasicAuthentication $true -WindowsAuthentication $true Set-ClientAccessServer -Identity "ex2016" -AutodiscoverServiceInternalUri https://autodiscover.contoso.local/Autodiscover/Autodiscover.xml New-MapiVirtualDirectory -Server "ex2016" -InternalUrl https://mail.contoso.local/mapi -ExternalUrl https://mail.contoso.local/mapi -IISAuthenticationMethods Ntlm, OAuth, Negotiate New-OabVirtualDirectory -Server "ex2016" -InternalUrl "https://mail.contoso.local/OAB" -ExternalUrl "https://mail.contoso.local/OAB" New-PowerShellVirtualDirectory -Server "ex2016" -Name Powershell -InternalUrl https://mail.contoso.local/PowerShell -ExternalUrl https://mail.contoso.local/PowerShell -RequireSSL:$false New-WebServicesVirtualDirectory -Server "ex2016" -InternalUrl "https://mail.contoso.local/EWS/Exchange.asmx" -ExternalUrl "https://mail.contoso.local/EWS/Exchange.asmx"
Restart IIS or reboot the Exchange Server host.
Now open the browser and login to the Exchange Admin Center (EAC) using the link https://ex2016.contoso.com/ECP. 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 recreated the virtual directories. Verify that all the Exchange virtual directories you re-created earlier are now displayed in the EAC console.
In the same way, you can reset and recreate all virtual directories (OAB, EWS, and Autodiscover) on Exchange 2019/2016/2013.
New-OwaVirtualDirectory: An Error Occurred While Creating the IIS Virtual Directory
In some cases, when re-creating a virtual directory in Exchange using New-OwaVirtualDirectory or New-OwaVirtualDirectory cmdlets, you may receive an error:
An error occurred while creating the IIS virtual directory `IIS://Exch2016/W3SVC/1/ROOT/ECP’
Or:
The AD configuration for virtual directory ‘owa’ already exists in ‘CN=xxx’ , please remove this AD configuration manually.
This error occurred because the IIS metabase left a record of the created virtual directory, 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 and IIS. The Get-EcpVirtualDirectory cmdlet (or a similar cmdlet for different virtual directories) gets information from AD, and not from 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 delete Exchange Server virtual directories using IIS Manager unless you are sure that their metadata 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. To do this, we need the Metabase Explorer tool from the IIS 6 Resource Kit (which requires Net Framework 3.5 Feature).
Launch IIS Metabase Explorer, go to Exchange > LM > W3SVC > 1 > ROOT. Delete the directory you want by right-clicking on it and choosing Delete.
Restart IIS:
iisreset /force
Now attempt to create the virtual directory again using the New-EcpVirtualDirectory, New-OwaVirtualDirectory, or New-WebApplication cmdlets.
5 comments
Thank You for thi!! Helped me fix an issue today!!
THANK YOU!
After fighting this for days this is the only solution that worked in my environment.
Following the steps, it took me about 5 minutes to solve my issue.
Don’t forget to change “ex2016\owa (Default Web Site)” to “your-server-name\owa (Default Web Site)”
Noticed EWS virtual directory not included above. Just wanting to confirm if more consideration for EWS? Having an issue with ews and thinking of blowing it out.
Thank you very helpful
Exchange 2013
after 23 update
Thanks helped me out fixing SBS 2011 issue I had with one dir