Method to export all site headers

Posted on 2009-02-10
Last Modified: 2012-05-06
Hi Experts,

I would like to know if there is a method to copy all site headers to a csv file. Rather than copy and paste each host header one by one.

Any suggestions how this can be done? I am using windows server 2003.


Question by:introlux

    Author Comment

    Note all I need is the host header in alphabetical order

    Author Comment

    I have at the moment to script below in VB that produces too much info. I only need the host header and preferably in alphabetical order.


    ' Enumerate IIS Configuration for Auditing
    DIM strServer, strServerType, strServerMetaType, objFile, strGuyFile, strFilePath
    DIM objService
    strServer = "localhost"
    strServerType = "Web"
    strServerMetaType = "W3SVC"
    strFilePath = "C:\IISAudit.csv"
    Set objFile = CreateObject("Scripting.FileSystemObject")
    Set strGuyFile = objFile.CreateTextFile(strFilePath, True)
    strGuyFile.WriteLine("ID,IP Address,Port,Host Header")
    IF WScript.Arguments.Length >= 1 THEN
        strServer = WScript.Arguments( 0 )
    END IF
    IF WScript.Arguments.Length = 2 THEN
        strServerType = WScript.Arguments( 1 )
        IF UCASE( strServerType ) = "FTP" THEN
            strServerType = "Ftp"
            strServerMetaType = "MSFTPSVC"
            strServerType = "Web"
            strServerMetaType = "W3SVC"
        END IF
    END IF
    SET objService = GetObject( "IIS://" & strServer & "/" & strServerMetaType )
    EnumServersites objService
    SUB EnumServersites( objService )
        DIM objServer, strBindings
        FOR EACH objServer IN objService
            IF objServer.Class = "IIs" & strServerType & "Server" THEN
                strGuyFile.WriteLine( _
                    objServer.Name & _
                ' Enumerate the HTTP bindings (ServerBindings) and
                ' SSL bindings (SecureBindings) for HTTPS only
                strBindings = EnumBindings( objServer.ServerBindings )
                'IF strServerType = "Web" THEN
                '    strBindings = strBindings & _
                '    EnumBindings( objServer.SecureBindings )
                'END IF
                'IF NOT strBindings = "" THEN
                '    WScript.Echo strBindings
                'END IF
            END IF
    FUNCTION EnumBindings( objBindingList )
        DIM i, strIP, strPort, strHost
        DIM reBinding, reMatch, reMatches
        SET reBinding = NEW RegExp
        reBinding.Pattern = "([^:]*):([^:]*):(.*)"
        FOR i = LBOUND( objBindingList ) TO UBOUND( objBindingList )
            ' objBindingList( i ) is a string looking like IP:Port:Host
            SET reMatches = reBinding.Execute( objBindingList( i ) )
            FOR EACH reMatch in reMatches
                strIP = reMatch.SubMatches( 0 )
                strPort = reMatch.SubMatches( 1 )
                strHost = reMatch.SubMatches( 2 )
                ' Do some pretty processing
                IF strIP = "" THEN strIP = "All Unassigned"
                IF strHost = "" THEN strHost = "*"
                'IF LEN( strIP ) < 8 THEN strIP = strIP & VbTab
                EnumBindings = EnumBindings & "," & _
                               strIP & "," & _
                               strPort & "," & _
                               strHost & ","
            EnumBindings = EnumBindings & VbCrLf
    FUNCTION State2Desc( nState )
        SELECT CASE nState
        CASE 1
            State2Desc = "Starting"
        CASE 2
            State2Desc = "Started"
        CASE 3
            State2Desc = "Stopping"
        CASE 4
            State2Desc = "Stopped"
        CASE 5
            State2Desc = "Pausing"
        CASE 6
            State2Desc = "Paused"
        CASE 7
            State2Desc = "Continuing"
        CASE ELSE
            State2Desc = "Unknown"
        END SELECT

    Open in new window

    LVL 70

    Accepted Solution


    It's been a while since I used this one... But it returns all domains used in all host headers in IIS and writes them to a file.

    It does not sort them into alphabetical order, is it really necessary for the script to do that? Or will you be using it in something like Excel which makes the task quite trivial?

    ' ListDomains
    ' Just a quick script to list the domains in use in IIS
    ' Author: Chris Dent
    ' Created: 04/05/2005
    ' Modified: 07/06/2005
    ' Runs for the local server by default
    strServer = "localhost"
    ' Filename you want stuff to go into
    strFileName = "c:\temp\DomainList.txt"
    ' Setup the output file
    Set objFileSystem = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFileSystem.CreateTextFile(strFileName, True, False)
    ' Connect to the Web Service
    Set objWebService = GetObject("IIS://" & strServer & "/W3SVC")
    For Each objWebServer in objWebService
      If objWebServer.Class = "IIsWebServer" Then
        arrBindings = objWebServer.Get("ServerBindings")
        For Each strBinding in arrBindings
          arrTemp = Split(strBinding, ":")
          objFile.WriteLine arrTemp(UBound(arrTemp))
      End If
    Set objFileSystem = Nothing
    Set objWebService = Nothing

    Open in new window


    Author Comment

    forget alphabetical order. will do it in excel
    i have run this but does not do anything

    Author Comment

    sorry it works!


    Author Closing Comment

    top answer

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Welcome to my series of short tips on migrations. Whilst based on Microsoft migrations the same principles can be applied to any type of migration. My first tip is around source server preparation. No migration is an easy migration, there is a…
    Welcome to my series of short tips on migrations. Whilst based on Microsoft migrations the same principles can be applied to any type of migration. My first tip Migration Tip #1 – Source Server Health can be found here: http://www.experts-exchang…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now