iisappcmd

IIS auto-generated webpage listing all websites being hosted


Essentially what the title says. Is there a feature-of/addon-for IIS which allows presenting in a single web page a list with links pointing to the websites hosted within IIS?

I know I can get said list from the command line via:

%windir%\system32\inetsrv\appcmd list site > c:\sites.xls

This will then create an Excel spreadsheet with the list of sites in IIS + site related information for each site.

But then I will have to parse the CSV file and turn it into html. This would work, but I'ld rather dodge it altogether if there already is a feature or an addon for the exact same thing out there.


Solution

  • You can use Powershell for this: you can loop through IIS sites, virtual directories, web applications and dynamically build a simple html page.

    Here is a simple script that creates an html file with a list of links to each virtual directory or web application. This is only a base script, you can customize it and add more details:

    #Import WebAdministration to manage IIS contents
    Import-Module WebAdministration
    
    #define a variable that will hold your html code
    $html = "<html>`n<body>"
    
    #define the root path of your sites (in this example localhost)
    $rootFolder = "http://localhost"
    
    $Websites = Get-ChildItem IIS:\Sites 
    
    #loop on all websites inside IIS
    foreach($Site in $Websites)
    {
        $VDirs = Get-WebVirtualDirectory -Site $Site.name
        $WebApps = Get-WebApplication -Site $Site.name
    
        #loop on all virtual directories    
        foreach ($vdir in $VDirs )
        {
        $html += "`n<a href='" + $rootFolder + $vdir.path +"'>" + $vdir.path + "</a><br/>"
        }
        #loop on all web applications
        foreach ($WebApp in $WebApps)
        { 
        $html += "`n<a href='" + $rootFolder + $WebApp.path +"'>" + $WebApp.path + "</a><br/>"
        }
    }
    #add final tags to html
    $html += "`n</body>`n</html>"
    
    #write html code to file
    $html >> "d:\sites.html" 
    

    For example with this IIS structure:

    enter image description here

    you get the following html:

    <html>
    <body>
    <a href='http://localhost/vd'>/vd</a><br/>
    <a href='http://localhost/test'>/test</a><br/>
    <a href='http://localhost/test2'>/test2</a><br/>
    </body>
    </html>
    

    that renders like this:

    enter image description here