How to Recreate/Reset IIS Virtual Directories (ECP, OWA) on Exchange Server 2019/2016/2013?

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, 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 a 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:

remove-owavirtualdirectory

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 and 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):

READ ALSO  How to Clear IIS Log Files on Windows Server 2012?

The same for ECP virtual directory:

Get-ECPVirtualDirectory

We are interested in the directory ecp (Default Web Site) on the server named EX2016.

recreate owa virtual directory exchange 2016

Display and remember 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.

exchange 2016 reset virtual directories

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”

new-owavirtualdirectory

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”

recreate ecp virtual directory

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

You can get info about other Exchange virtual directories by using the EMS cmdlets:

Get-AutodiscoverVirtualDirectory

Get-OABVirtualDirectory

Get-MapiVirtualDirectory

Get-ActiveSyncVirtualDirectory

Get-PowerShellVirtualDirectory

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)"

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://www.mail.contoso.local/PowerShell -ExternalUrl https://mail.contoso.local/PowerShell -RequireSSL:$false

In the same way, you can reset and recreate all other virtual directories on Exchange 2019/2016/2013, for example, OAB, EWS, and Autodiscover.

READ ALSO  Building IIS Web Farm with Load Balancing using Nginx

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’

remove-ecpvirtualdirectory

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.).

new-ecpvirtualdirectory

If the directory is still in IIS but not present in the Active Directory configuration, you must remove it from the IIS configuration. To do this, we need the Metabase Explorer tool from the IIS 6 Resource Kit (requires Net Framework 3.5 Feature).

READ ALSO  How to Setup FTP Server in Windows 10?

Launch IIS Metabase Explorer, go to Exchange > LM > W3SVC > 1 > ROOT. Delete the directory you want by right-clicking on it and choosing Delete.

recreate owa virtual directory

Restart IIS:

iisreset /force

Now attempt to create the virtual directory again using the New-EcpVirtualDirectory, New-OwaVirtualDirectory, or New-WebApplication cmdlets.

Cyril Kardashevsky

2 comments

  1. 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)”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.