If you develop web applications for IIS, or administrate IIS and file systems, you sooner or later end up with orphaned IIS application which point to non-existing directories.
To get an overview of IIS applications, start up PowerShell in administrator mode (I prefer PowerShell ISE) and run
import-module webadministration dir "IIS:\\sites\Default Web Site"
To exclude any files that reside in IIS root, filter out the “file” entries:
import-module webadministration dir "IIS:\\sites\Default Web Site" | where { $_.NodeType.Trim() -ne "file" }
Finally, we test the Physical Path property of the resulting entries
import-module webadministration dir "IIS:\\sites\Default Web Site" | where { $_.NodeType.Trim() -ne "file" -and ![System.IO.Directory]::Exists( $_.PhysicalPath ) }
This command lists all IIS web application and virtual root directories which point to non-existing directories. The result looks like this:
Type Name Physical Path ---- ---- ------------- application application1 D:\app\app1 application web2 D:\app\web2