Removing phantom applications from Application Pools in IIS7

Solution 1:

Since I had the same issue; application pools with applications that did not exist anymore, I did some research and finally managed to solve the issue.

Here are some steps:

  1. Locate and edit your IIS 7 configuration file "applicationHost.config" with a text editor. It should be stored in "C:\windows\system32\inetsrv\config" Since the folder is somehow "protected", I usually edit like the following:
    1. Open Windows Explorer
    2. Navigate to "C:\windows\system32\inetsrv\config"
    3. Copy the file "applicationHost.config"
    4. Paste it to a folder where you can edit it, e.g. your Desktop
    5. Open it with your editor of choise and edit it
    6. Copy it back with Windows Explorer to "C:\windows\system32\inetsrv\config"
  2. Make a backup of your "applicationHost.config" file!
  3. Search with a text editor in your "applicationHost.config" for your non-existing applications. They should be located somewhere inside an <application ...> XML node.
  4. Delete the <application ...> node(s) of all your phantom applications.
  5. Save the file and copy it back to "C:\windows\system32\inetsrv\config"
  6. Refresh the IIS management console. Your application pools should now be without the phantom applications you previously deleted.
  7. Actually remove the now empty application pool.

That worked for me, if it does not work for you, please post a comment here. A good help was this posting on the IIS forum.

Please be also aware that when editing the "applicationHost.config" file directly in its original location, you need to use a 64-bit editor (e.g. Notepad++ 64-bit), because otherwise it would get stored in "C:\Windows\SysWOW64\inetsrv\Config" instead of the correct location.

Solution 2:

This is probably safer and simpler than editing applicationHost.config.

Powershell  
PS C:\Windows\system32> import-module WebAdministration
PS C:\Windows\system32> iis:
PS IIS:\> cd .\AppPools
PS IIS:\AppPools> ls
PS IIS:\AppPools> del [name of phantom AppPool]  

Solution 3:

Child applications aren't automatically deleted and the IIS Manager can't display them in the tree, so that's your problem...

A quick and robust way is to use a PowerShell script to get all applications, test whether the physical path still exists and if not, delete the application:

# This is for IIS 7, make sure the snap-in is installed first: https://www.iis.net/downloads/microsoft/powershell
Add-PSSnapin WebAdministration

# Get all IIS sites
Get-ChildItem IIS:\Sites | foreach {
    $site = $_;

    # Get all applications without existing physical path
    $applications = Get-ChildItem $site.PsPath | Where-Object { $_.NodeType -eq "application" -and (Test-Path $_.PhysicalPath) -eq $False };

    # List all phantom applications
    $applications | FT

    # Remove applications
    $applications | Remove-WebApplication -Site $site.Name
}