HOWTO: Enumerate IIS website configuration (VBScript using ADSI)


A powerful but often under-utilized and misunderstood feature of IIS is its programmatic configuration APIs. On the one hand, all IIS administrative APIs allow programmatic, automated, and unattend configuration of IIS. On the other hand, it can be hard to choose which administration model (and resulting API) to use, and sample code to get started on the interfaces are hard to come by, as the following question illustrates…


Question:


Hi, all.


My ultimate goal is to script out a solution which you would get if you opened up IISAdmin and exported the website list to a file. If someone knows of where something like that can be found, please let me in on it.


I’ve manage to cobble the below together after several hours of rooting through Google and the MSDN pages…


Set IISOBJ = getObject(“IIS://LocalHost/W3SVC”)
For each Object in IISOBJ
        if (Object.Class = “IIsWebServer”) then
                WScript.Echo “server name? ” & ” Description ” &
Object.ServerComment & ” Identifier ” & Object.Name  & ” State, up or
down? ” & Object.ServerState & ” Headers? ” & ” IP address? ” & ” port?
” & ” SSL Port? “
        end if
next


I think I’m spinning my wheels at this point, there’s a number of items I’m still missing, like getting a website state, headers, site IP address and port information. Any thoughts or good pointers on how to get it?


I’ve got a decade more unix scripting knowledge under my belt, but it’s pretty useless to me in this instance.


Thanks for your time.


Answer:


Well, hopefully, you do not need to look further than here. 🙂


Based on your example code, it appears that you are looking for a VBScript based script using the IIS ADSI API. I whipped together a fairly detailed starter sample at the end of this entry to do what you are asking for, including:



  • Enumerate all websites on a given server or a remote server (assumes running user has necessary credentials on remote server).
  • Display all HTTP/HTTPS bindings of each website (IP, Port, Host Header)
  • Runtime state (such as whether the website is started, stopped, paused, etc)
  • Some other properties, like Log file directory and friendly website description

This sample should have enough details to get you started. Use <EnumWebSites.vbs> [RemoteServerName] to enumerate websites on a remote server.


Example output:

Enumerating websites on localhost

Site ID = 1
Comment = “Default WebSite”
State = Started (MD_SERVER_STATE_STARTED)
LogDir = %WinDir%\System32\LogFiles
IP Address Port Host
All Unassigned 80 *
1.2.3.4 81 *
12.34.56.78 82 HostHeader
All Unassigned 443 *

Site ID = 2
Comment = “Administration Web Site”
State = Started (MD_SERVER_STATE_STOPPED)
LogDir = %WinDir%\System32\LogFiles
IP Address Port Host
All Unassigned 8734 *
All Unassigned 443 *


Here are some other useful links (if you want to enumerate other website properties or even other objects like Virtual Directories or Web Applications):



If you have other questions, feel free to post comments on this post or send them via the blog’s “contact” link.


Enjoy.


//David

OPTION EXPLICIT

DIM CRLF, TAB
DIM strServer
DIM objWebService

TAB = CHR( 9 )
CRLF = CHR( 13 ) & CHR( 10 )

IF WScript.Arguments.Length = 1 THEN
strServer = WScript.Arguments( 0 )
ELSE
strServer = “localhost”
END IF

WScript.Echo “Enumerating websites on ” & strServer & CRLF
SET objWebService = GetObject( “IIS://” & strServer & “/W3SVC” )
EnumWebsites objWebService

SUB EnumWebsites( objWebService )
DIM objWebServer, strBindings

FOR EACH objWebServer IN objWebService
IF objWebserver.Class = “IIsWebServer” THEN
WScript.Echo _
“Site ID = ” & objWebserver.Name & CRLF & _
“Comment = “”” & objWebServer.ServerComment & “”” ” & CRLF & _
“State = ” & State2Desc( objWebserver.ServerState ) & CRLF & _
“LogDir = ” & objWebServer.LogFileDirectory & _
“”

‘ Enumerate the HTTP bindings (ServerBindings) and
‘ SSL bindings (SecureBindings)
strBindings = EnumBindings( objWebServer.ServerBindings ) & _
EnumBindings( objWebServer.SecureBindings )
IF NOT strBindings = “” THEN
WScript.Echo “IP Address” & TAB & _
“Port” & TAB & _
“Host” & CRLF & _
strBindings
END IF
END IF
NEXT

END SUB

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 & TAB

EnumBindings = EnumBindings & _
strIP & TAB & _
strPort & TAB & _
strHost & TAB & _
“”
NEXT

EnumBindings = EnumBindings & CRLF
NEXT

END FUNCTION

FUNCTION State2Desc( nState )
SELECT CASE nState
CASE 1
State2Desc = “Starting (MD_SERVER_STATE_STARTING)”
CASE 2
State2Desc = “Started (MD_SERVER_STATE_STARTED)”
CASE 3
State2Desc = “Stopping (MD_SERVER_STATE_STOPPING)”
CASE 4
State2Desc = “Stopped (MD_SERVER_STATE_STOPPED)”
CASE 5
State2Desc = “Pausing (MD_SERVER_STATE_PAUSING)”
CASE 6
State2Desc = “Paused (MD_SERVER_STATE_PAUSED)”
CASE 7
State2Desc = “Continuing (MD_SERVER_STATE_CONTINUING)”
CASE ELSE
State2Desc = “Unknown state”
END SELECT

END FUNCTION

Comments (77)

  1. Someone says:

    Nice work, thanks

  2. Steve says:

    This was just what I needed.

  3. Willy Chang says:

    Thanks. This script saves me a lots of time.

  4. Levi says:

    I am trying to use this script, and other IIS scripts that use "SET objWebService = GetObject( "IIS://" & strServer & "/W3SVC" )"

    And I am repeatedly getting  "(null): Invalid syntax"

    Anyone have any insight?

    Thanks,

    Levi

  5. Levi says:

    Actually I can run the script locally on the server but not from my workstation.

    Levi

  6. David.Wang says:

    Levi – Make sure that IIS is actually installed on the machine you are trying to launch the script (the workstation).

    Since the GetObject() syntax is ADSI, it requires the IIS ADSI provider to be installed on both the local and remote machine… even if you are only trying to get a remote ADSI object.

    //David

  7. Tony says:

    I get a Type mismatch when I try to access the ServerBindings property.

    Any idea why?

  8. David.Wang says:

    Tony – Can you show the exact code snippet where you are trying to "access" the ServerBindings property that results in "Type mismatch".

    //David

  9. Justin says:

    Absolutely brilliant! I have a machine with over 50 websites on it each with multiplehost headers. This has saved me hours, thankyou VERY much!

  10. David.Wang says:

    Steve, Willy, Justin – thanks. It is what I am hoping to be able to do – provide a useful commandline tool to perform some tasks and also be a good sample for user customization – and in the end, save everyone time/effort.

    //David

  11. HUNG_NGO says:

    Hi,

    This script save me a lot of time. By the way, can you tell me how can I start and stop SSL service on a particular page!? Where can I find the full tutorial about the ADSI?

    Anyway, thanks a lot!

    Hung.

  12. David.Wang says:

    Hung_Ngo – I suggest reading Microsoft’s MSDN online for the information you want, especially Script Center, which contains tons of sample script code to do just about every action for many Microsoft products.

    I do not understand what you mean by "stop and start SSL service on a particular page" – please clarify what you are trying to do.

    //David

  13. HUNG_NGO says:

    Hi David,

    I have found the solution. The key is on 2 KeyType w3svc/1/root/website/AccessSSL and w3svc/1/root/website/AccessSSL128.

    Anyway, thanks much,

    Hung.

  14. Mike says:

    How do you get the output to a text file – instead of the gui pop screens?

    thanks

    Mike

  15. David.Wang says:

    Mike – Windows support running scripts in multiple "hosts" which may display output either in a console window or as popup dialogs.

    Default host is WSCRIPT, which shows popup dialogs.

    You want to use CSCRIPT, which shows output to console window and can be piped into a text file.

    Either:

    1. Launch the script one-time with CSCRIPT.EXE:

     CSCRIPT EnumWebsites.vbs

    2. Change the default script host to CSCRIPT with:

     CSCRIPT //h:cscript

     EnumWebsites.vbs

    //David

  16. Alex says:

    Thanks for this … two questions:

    1. How could I do the same for FTP sites and …

    2. How can I modify values for both?

  17. David Wang says:

    I recently got a request to make a script to illustrate how to enumerate useful values from both Web…

  18. David.Wang says:

    Alex – FTP configuration works the same way as W3SVC. You can use ADSI to read and write values for both; this script shows how to read them, and if you use assignment instructions instead of read and then call SetInfo() on the objects with changed values, you’d record the modified values.

    As for how to do the same for FTP sites:

    http://blogs.msdn.com/david.wang/archive/2006/06/08/HOWTO_Enumerate_IIS_website_and_ftpsite_configuration_VBScript_using_ADSI.aspx

    //David

  19. David, the website is awesome. thanks for your effort and answering the kinds of IIS questions that dont seem to have been answered in the last 10 years.

    Am I missing something? There seems to be no iterators for active sessions in the IIS model. I can find the "active session count", but, can’t find a collection of sessions that can be iterated. Does such a collection exist?

  20. David.Wang says:

    MikeMontana – there are no APIs to retrieve current runtime state, like "active sessions" in IIS. Technically, IIS has no idea about "sessions" – it only knows about requests and connections – so application frameworks like ASP/ASP.Net can offer such behavior, which is completely up to the individual frameworks.

    //David

  21. Mesut says:

    how can i take (site id) in the (Comment) possision.

  22. Paul says:

    Great script. One thing tough. How can one add a listing of the Application Pool each site belongs to ?

  23. Paul says:

    ..and howto add a listing to the homedir folder path where the files for the site’s located ?

  24. James says:

    very useful!!!

    well, any idea how I can get the same result by using asp.net code? Then I shall be able to access those information from "outside" of the server.

  25. jamesd says:

    I guess I could use asp.net code to run VBScript too, but I do prefer, if it is possible, to use pure asp.net code to get the same result.

  26. kathyyunli@yahoo.com says:

    Hi David,

    I need get the latest created Site ID. The iisweb create a site with random large number, we don’t want to use these number for site ID. Instead we want to use sequence number, for example, 1,2,3,4. We want to use script to get the largest sequence number among all the IIS web sites, then use createNewSite by passing this SITEID +1 into the parameters.

    Could you provide the script for us to find the latest created site ID? Thanks

  27. David.Wang says:

    Kathy – I really think you should reconsider what you are doing.

    I do not think it is a good idea to create and use sequential site ID because the ID is an internal implementation detail of IIS not meant for end-user consumption.

    For example, what happens when you move to IIS7 and Site ID becomes deprecated? What happens when you move to IIS6 and Site ID is no longer sequential?

    Instead of fighting to keep sequential site ID, you should write your code to not use site ID. IIS6 generates the Site ID based on a hash of the website’s friendly name, so it is possible to create sites with matching IDs on multiple computers (for synchronization) – without knowing the site ID itself

    Thus, I refrain from providing non-optimal legacy code that I know will be broken in the future.

    //David

  28. Doc says:

    This script leaves out gather any info on child VDir websites.

  29. David.Wang says:

    Doc – Please search for and see this blog entry: http://blogs.msdn.com/david.wang/archive/2007/12/19/howto-list-all-virtual-directories-and-paths-of-a-list-of-servers.aspx

    Read my BIO for the answer to why and what I blog the way I do.

    In short, saying "this script doesn’t do X" is just complaining. Now, it has never been anyone’s responsibility to resolve your complaints, so voicing them really gets nothing.

    Now, it is much, much better to ask "how to do X" and then do it yourself… and I will certainly help anyone learn how to do X.

    //David

  30. Doc says:

    You’re correct and my apologies then.

    I guess I’ve been posting on CodeProject too much.

  31. anne says:

    what a wonderful tool. you rock!  thanks.

  32. Patrick says:

    We just took over a company that had hundreds of websites on old NT4 boxes… This tool has saved us a huge amount of work… many thanks

  33. Bryan Ferriby says:

    I would like to allow my web designer to be able to add a Index.asp document to a website and then move it up to the top of the list.  I dont want them to use the IIS interface as it allows too much scope for messing up.  

    Anyone got any ideas?

  34. Richard Bailey says:

    Here is a convergence and alteration of the above script – that does a ping test first.  Ping-test example comes from here: http://www.scriptinganswers.com/vault/Registry/

    the script below is nasty, and has has some hard coded paths which could easily be cleaned up by someone who needed to run it regularly… I just needed it to run once to collect all of the websites, siteid, and logfile path for about 200 web servers.

    ‘begin

    Const HKEY_LOCAL_MACHINE = &H80000002

    Const ForAppending = 8

    DIM strServer

    DIM objWebService

    Dim objFSO, objFolder, objShell, objFile, objFSOText, strDirectory, strFile, objTextFile

    strDirectory = "c:tempsite_collection"

    strFile = "web_site_logdir_collection.csv"

    ‘ Grab computer names from a list and insert into the script

    Set objFSO = Wscript.CreateObject("Scripting.FileSystemObject")

    Set objFile = objFSO.OpenTextFile("c:tempsite_collectionComputerList.txt")

    ‘ Create files for logging errors

    Set objNoPing = objFSO.CreateTextFile("c:tempsite_collectionNoPing.txt")

    Set objErrorLog = objFSO.CreateTextFile("c:tempsite_collectionErrorLog.txt")

    Set objFSO2 = CreateObject("Scripting.FileSystemObject")

    Set objTextFile = objFSO2.OpenTextFile (strDirectory & strFile, ForAppending, True)

    ‘ Read through text stream

    Do Until objFile.AtEndOfStream

    strServer = Trim(objFile.ReadLine)

    On Error Resume Next

    ‘Test to see if the computer is reachable by ping

    If IsAlive(strServer) = TRUE Then

    ‘ get IIS info

    SET objWebService = GetObject( "IIS://" & strServer & "/W3SVC" )

    EnumWebsites objWebService

    If Error <> 0 Then

    objErrorLog.Writeline "Error on " & strServer & ":" & Err.Number & ", " & Err.Description

    End If

    ‘ Write a line to the leftovers file to be run against later

    ElseIf IsAlive(strServer) = FALSE Then

    objNoPing.Writeline strServer

    End If

    ‘ Loop through to next computer in textfile

    Loop

    ‘ At end of text stream, close open files

    objFile.Close

    objNoPing.Close

    objErrorLog.Close

    SUB EnumWebsites( objWebService )

       DIM objWebServer, strSecureBind, strServerBind, strBindings, strOutput, strEnd, intLength

       FOR EACH objWebServer IN objWebService

           IF objWebserver.Class = "IIsWebServer" THEN

               ‘WScript.Echo objWebserver.Name & ";" & objWebServer.ServerComment & ";" & State2Desc( objWebserver.ServerState ) & ";" & objWebServer.LogFileDirectory

               strOutput = strServer & ";" & objWebserver.Name & ";" & objWebServer.ServerComment & ";" & State2Desc( objWebserver.ServerState ) & ";" & objWebServer.LogFileDirectory

               ‘ Enumerate the HTTP bindings (ServerBindings) and

               ‘ SSL bindings (SecureBindings)

               strSecureBind = EnumBindings( objWebServer.SecureBindings )

       strServerBind = EnumBindings( objWebServer.ServerBindings )

               strOutput = strOutput & ";" & strServerBind & ";" & strSecureBind

           objTextFile.WriteLine(strOutput)

    ‘Wscript.Echo strOutput

           END IF

       NEXT

    END SUB

    ‘ ===============================================================================================================================

    Function IsAlive(strHost)

    ‘ Returns True if Host responds to ping

    ‘ strHost is a hostname or IP

    Const OpenAsASCII = 0

    Const FailIfNotExist = 0

    Const ForReading =  1

    Dim objShell, objFSO, sTempFile, fFile

     Set objShell = CreateObject("WScript.Shell")

     Set objFSO = CreateObject("Scripting.FileSystemObject")

       sTempFile = objFSO.GetSpecialFolder(2).ShortPath & "" & objFSO.GetTempName

       objShell.Run "%comspec% /c ping.exe -n 2 -w 500 " & strHost & " >" & sTempFile, 0 , True

     Set fFile = objFSO.OpenTextFile(sTempFile, ForReading, FailIfNotExist, OpenAsASCII)

     Select Case InStr(fFile.ReadAll, "TTL=")

            Case 0

               IsAlive = False

            Case Else

               IsAlive = True

       End Select

       fFile.Close

        objFSO.DeleteFile(sTempFile)

       Set objFSO = Nothing

       Set objShell = Nothing

    End Function

    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 & ":"

               EnumBindings = EnumBindings & ":" & strIP & ":" & strPort & ":" & strHost & ""

           NEXT

       NEXT

    END FUNCTION

    FUNCTION State2Desc( nState )

       SELECT CASE nState

       CASE 1

           State2Desc = "Starting (MD_SERVER_STATE_STARTING)"

       CASE 2

           State2Desc = "Started (MD_SERVER_STATE_STARTED)"

       CASE 3

           State2Desc = "Stopping (MD_SERVER_STATE_STOPPING)"

       CASE 4

           State2Desc = "Stopped (MD_SERVER_STATE_STOPPED)"

       CASE 5

           State2Desc = "Pausing (MD_SERVER_STATE_PAUSING)"

       CASE 6

           State2Desc = "Paused (MD_SERVER_STATE_PAUSED)"

       CASE 7

           State2Desc = "Continuing (MD_SERVER_STATE_CONTINUING)"

       CASE ELSE

           State2Desc = "Unknown state"

       END SELECT

    END FUNCTION

  35. Richard Bailey says:

    P.S. to post above:

    the following would be the header for the .csv file created, if you needed to import it

    Server; Site ID ; Comment ; State ; LogDir ; Standard IP Address:Port:Host:; Secure IP Address:Port:Host:

  36. David.Wang says:

    Richard – thanks for the post back.

    Personally, I think it is far easier and cleaner to write a tiny three line batch file wrapper around this script to do what you have added.

    FOR /F %I IN ("c:tempsite_collectionComputerList.txt") DO (

       PING -w 500 -n 2 %I

       REM if server exists ERRORLEVEL=0; otherwise it is 1

       CSCRIPT EnumSite.vbs %I

    )

    With a tiny bit of ambition, one can easily compose your desired solution out of existing code. Reordering output into csv and txt format is likely one-liners with a batch wrapper around VBScript — which is how I’d recommend performing most administrative tasks.

    When the tool doesn’t do it all, use shell script glue to make it happen.

    If this was in Powershell it would be even nicer.

    //David

  37. Nick says:

    Hi, thanks for the great script. However, I can’t seem to get it running. When I run cscript siteslist.vbs I get access denied and a google search hasn’t helped me. Even when I just run cscript I get an access denied. Can you point me in the direction of some solution? Thanks.

  38. David.Wang says:

    Nick – unfortunately, it sounds like you are in an environment which prevents users from running scripts, and I will not be able to help your circumvent your environment’s security measures.

    //David

  39. Peter Lewis says:

    How do you enumerate the current list of IP Addresses on the server?

    The IIS Management snap-in does this of course, but I cannot find what method I would use to complete this action.

    The purpose would be so I can enumerate the list of available IPs on the server so when I use the server binding, I can populate a listbox/combobox for ip selection rather than ip entry.

    I hope you can point me in the right direction. Thanks and great article!

    – Peter

  40. SAM says:

    I have run into a problem running my vbscript during an install. When the targeting a Server 2008 machine with IIS 7 and IIS 6 compatability disabled, the script fails on the line

    Set objW3SVC = GetObject("IIS://localhost/W3SVC")

    I would rather not require IIS 6 compatabilty. Is there an easy way in vbscript to enumerate the websiltes on IIS7?

  41. David.Wang says:

    SAM – all of my scripts require IIS6 Metabase Compatibility to run on IIS7. This is because they use ADSI, which requires the IIS6 Metabase Compatibility feature on IIS7.

    There is a new WMI and COM provider for IIS7 but code for that is IIS specific. Depending on the concepts I am illustrating, I would use different APIs. For examples, websites/vdir/ISAPI have always existed and use classic API. While Modules/Handlers originate from IIS7 and only use IIS7-specific APIs.

    You can use APPCMD.EXE in %windir%System32inetsrv to do many of the common (but not all) configuration-related tasks. You will have to read the help to determine the syntax.

    //David

  42. Michael says:

    I get the error: C:web_info.vbs(17, 1) (null): Invalid syntax

    when I run the script.

    This is line 17:

    set objWebService = GetObject( "IIS://" & strServer & "/W3SVC" )

    Does this mean I need to run the script from a server with IIS installed? Is there a way to run this from a XP machine w/o IIS to W2k3 machines that do?

    Thanks.

  43. David.Wang says:

    Michael – you need to run this script on machines with IIS installed in order to query remote machines with IIS installed, using ADSI.

    You won’t be able to query IIS6-specific properties with ADSI from XP Pro 32bit — for example, AppPoolId. In this case, you are querying common properties that exist both in IIS on XP and W2K3, so it is fine.

    //David

  44. dave says:

    thankyou thankyou thankyou!!!!!

    this script is exactly what i needed to obtain site ID’s for a site to then use in another script to set the SSL host headers.

  45. dave says:

    I modified the script slightly for my purposes and thought i’d share.

    This asks for a website name and then uses David’s script to locate the site identifier for that name.

    It then runs adsutil.vbs with that identifier to set the port 80 and port 443 site headers.

    i had to do this because the IIS Manager GUI doesn’t have an option to set site headers for SSL !? Why, I have no idea… and then they go and provide us a cmd line script to do it, but that script requires the numeric site id, which is difficult to easily find out..  Hence thanks to David’s code and a little bit of addition, I was able to script this nicely so any of our administrators could do it with ease.

    ‘—————————————————————-

    ‘—- Set WebSite Headers.vbs —-

    ‘   Written by Dave – 25.6.08

    ‘   Code for interogating IIS metabase to obtain SiteName (site identifier)

    ‘   obtained from David Wang (http://blogs.msdn.com/david.wang)

    ‘   Script uses IIS Admin Script "adsutil.vbs" which must exist

    ‘   (installed by default with IIS 6.0)

    ‘—————————————————————-

    OPTION EXPLICIT

    DIM CRLF, TAB

    DIM strServer, strSiteName, strRun

    DIM objWebService, objShell

    TAB  = CHR( 9 )

    CRLF = CHR( 13 ) & CHR( 10 )

    SET objShell = Wscript.CreateObject("Wscript.Shell")

    SET objWebService = GetObject( "IIS://" & strServer & "/W3SVC" )

    strServer = "localhost"

    DO

    strSiteName = Inputbox("This script will edit the IIS metabase to include header bindings for port 80 and SSL port 443." & vbCrLf & vbcrlf & "Enter the IIS Website name" & vbCrLf & "eg. swanhill.munitec.com.au", "Set Website headers", "council.munitec.com.au")

    LOOP UNTIL strSiteName <> "council.munitec.com.au"

    if instr(strSiteName,".") < 1 then

    msgbox "Not a proper domain name – website name must be a fully qualified domain name"

    wscript.quit

    end if

    ‘————————

    ‘– run script to set headers

    EnumWebsitesSetHeader objWebService

    ‘– print out web site info & new bindings

    EnumWebsites objWebService

    SUB EnumWebsitesSetHeader( objWebService )

       DIM objWebServer, strBindings

       FOR EACH objWebServer IN objWebService

           IF objWebserver.Class = "IIsWebServer" THEN

    if ucase(objWebServer.ServerComment) = ucase(strSiteName) then

    strRun = "cscript.exe C:InetpubAdminScriptsadsutil.vbs set /w3svc/" &_

    objWebServer.Name & "/SecureBindings " &_

    """:443:" & strSiteName & """  "

    objShell.Run strRun, 0, True

    strRun = "cscript.exe C:InetpubAdminScriptsadsutil.vbs set /w3svc/" &_

    objWebServer.Name & "/ServerBindings " &_

    """:80:" & strSiteName & """  "

    objShell.Run strRun, 0, True

    end if

           END IF

       NEXT

    END SUB

    SUB EnumWebsites( objWebService )

       DIM objWebServer, strBindings

       FOR EACH objWebServer IN objWebService

           IF objWebserver.Class = "IIsWebServer" THEN

    if ucase(objWebServer.ServerComment) = ucase(strSiteName) then

            WScript.Echo _

            "Site ID = " & objWebserver.Name & CRLF & _

                   "Server Comment = """ & objWebServer.ServerComment & """ " & CRLF & _

    "State   = " & State2Desc( objWebserver.ServerState ) & CRLF & _

                    ""

               ‘ Enumerate the HTTP bindings (ServerBindings) and

               ‘ SSL bindings (SecureBindings)

               strBindings = EnumBindings( objWebServer.ServerBindings ) & _

                             EnumBindings( objWebServer.SecureBindings )

               IF NOT strBindings = "" THEN

                    WScript.Echo "IP Address" & TAB & _

                           "Port" & TAB & _

                           "Host" & CRLF & _

                           strBindings

               END IF

    end if

           END IF

       NEXT

    END SUB

    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 & TAB

               EnumBindings = EnumBindings & _

                              strIP & TAB & _

                              strPort & TAB & _

                              strHost & TAB & _

                              ""

           NEXT

           EnumBindings = EnumBindings & CRLF

       NEXT

    END FUNCTION

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

       END SELECT

    END FUNCTION

  46. David.Wang says:

    dave – Nice script.

    I would have used this script to find the IIS Website ID with another one of my scripts that modify HTTP/SSL Bindings ( http://blogs.msdn.com/david.wang/archive/2004/12/02/273681.aspx ) and tie the two together with a little batch file scripting such that makes this chore incredibly short and clean and with completely reusable stand-alone scripts.

    The reason IIS6 UI does not set Host headers for SSL is because:

    1. It is prohibited to alter/add UI inside of a Windows Service Pack. To do so would involve re-localization for all Windows Languages as well as a whole bunch of other work and government red-tape that end up making it not worth doing in a Service Pack.

    2. SSL Host headers was a bug-fix "feature" added in WS03 Service Pack 1 for HTTP.SYS for the benefit of IIS6

    Thus, it was either:

    1. Wait for Windows Server 2008 to release IIS with support for SSL Host headers

    2. Add SSL Host headers in WS03SP1, without UI, but a whole bunch of documents telling you how to do it

    I believe you’d think that we made the right choice.

    //David

  47. Michiel Bester says:

    Excellent work. 2 seconds to get a complete listing – and that 2 seconds included the copying of the text and renaming the vbs file:-)

  48. Get Physical Path of a WebSite says:

    Hi David,

    Thanks for sharing the information.

    I have a requirement to get the "Physical Path" of a web site.

    In general its value for Default Web Site will be "%SystemDrive%inetpubwwwroot".

    What property name of  "IIsWebServer" should I use to get the "Physical Path" of a web site?

    GIRI

  49. David.Wang says:

    Giri – There is no such thing as "physical path" of a website. So, the property you are looking for does not exist.

    You can only retrieve the physical path of a certain URL, and you need to read the "Path" property of the "IIsWebVirtualDir" object to get that value.

    //David

  50. Amit Batra says:

    I am able to get physical path of virtual directories from iis but not if i set websites at different ports instead of creating virtual directories.

    Please help..

  51. Xman says:

    Hello, How can we get properties of virtualdir under IIS://" & strServer & "/W3SVC/N/myspace ?

  52. David.Wang says:

    Xman – I suggest looking at how %SYSTEMDRIVE%InetpubAdminScriptsADSUTIL.VBS does it when you run:

     CSCRIPT %SYSTEMDRIVE%InetpubAdminScriptsADSUTIL.VBS ENUM W3SVC/N/myspace

    //David

  53. ganesh says:

    Advice me the script to list the website name, port number, host header, IP, SSL, and auth in all the application in the server..

  54. CodeGecko says:

    This is awesome, it’s saved me hours of time in the middle of a crisis.

    Thanks!

  55. Atomic says:

    Hi David,

    your script is great! I have one question though, what if I have multiple servers to query, e.g. 100 servers to check and  not just the local machines, how do I modify the script to accomodate it?

  56. Ramesh says:

    Hi David,

    I get the following error when I try running the script.

    Line:17

    Char: 1

    Error: 0x80005000

    Code: 80005000

    Source: (null)

    I can run the script on the local host but when I specify a server within the domain i get the above error.

  57. Ratish says:

    The Script is awesome. Can someone get me a script which pulls up authentication for Default website and all other VDir’s in IIS ??

    Ratish

  58. DavidR says:

    Hi Guys,

    Have edited David’s script to include listing of home directory for website content per site and also output to a txt file.

    http://satchelmouth.wordpress.com/2009/05/28/script-to-list-important-details-for-all-websites-in-iis6/

    ( I couldn’t seem to post the entire script contents here, maybe a character limit? )

  59. darian says:

    Hi All,

    My IIS 6 server has become a little bit of a mess and I’d like to update the ServerComment (IIS site name) from the metabase to match the primary host header value.

    Has anyone done that before?

    thanks

    darian

  60. vuadapass says:

    Excellent work. 2 seconds to get a complete listing – and that 2 seconds included the copying of the text and renaming the vbs file:-)

  61. Tim says:

    David:

    I’m trying to access the ‘objServer.DefaultDoc’ value(s).  I can retrieve the values but if I update the value (add/remove a document), the ‘DefaultDoc’ value remains unchanged.

    Any ideas on how to get the current values?

  62. Tom says:

    Hi David.  Thanks for the great blog.  

    This code returns a WMI ‘Provider Load Failure’ against an IIS7 server even with "IIS6 WMI Compatibility" installed.  But it will work if I add "IIS6 Metabase Compatibility".  

    So question #1 is ‘Am I missing something?’

    And question #2 is ‘How strongly should I bother resisting enabling IIS6 Metabase Compatibility — is it that big of a deal?’

    Set objWMIService = GetObject("winmgmts:{authenticationLevel=pktPrivacy}!\servernamerootMicrosoftIISv2")

    Set colItems = objWMIService.ExecQuery("SELECT * FROM IIsApplicationPools_IIsApplicationPool", "WQL", &h10 + &h20)

    Result = "AppPools" & vbcrlf

      For Each objItem In colItems

         Result = Result & objItem.PartComponent & vbcrlf

      Next

    WScript.Echo Result

    Thanks so much!

  63. Excellent work. 2 seconds to get a complete listing – and that 2 seconds included the copying of the text and renaming the vbs file:-)

  64. sieure says:

    Hi David,

    Thanks for sharing the information.

    I have a requirement to get the "Physical Path" of a web site.

    In general its value for Default Web Site will be "%SystemDrive%inetpubwwwroot".

    What property name of  "IIsWebServer" should I use to get the "Physical Path" of a web site?

    GIRI

  65. Blackberry says:

    Set objWMIService = GetObject("winmgmts:{authenticationLevel=pktPrivacy}!\servernamerootMicrosoftIISv2")

    Set colItems = objWMIService.ExecQuery("SELECT * FROM IIsApplicationPools_IIsApplicationPool", "WQL", &h10 + &h20)

    Result = "AppPools" & vbcrlf

     For Each objItem In colItems

        Result = Result & objItem.PartComponent & vbcrlf

     Next

    WScript.Echo Result

    Thanks so much!

  66. Bảo Hiểm says:

    Excellent work. 2 seconds to get a complete listing – and that 2 seconds included the copying of the text and renaming the vbs file:-)

  67. Rap says:

    SAM – all of my scripts require IIS6 Metabase Compatibility to run on IIS7. This is because they use ADSI, which requires the IIS6 Metabase Compatibility feature on IIS7.

    There is a new WMI and COM provider for IIS7 but code for that is IIS specific. Depending on the concepts I am illustrating, I would use different APIs. For examples, websites/vdir/ISAPI have always existed and use classic API. While Modules/Handlers originate from IIS7 and only use IIS7-specific APIs.

  68. Brian says:

    Thank u for the script.  I modified it a little bit to show the IP of the server.

    OPTION EXPLICIT

    DIM CRLF, TAB

    DIM strServer

    DIM objWebService

    DIM strcomputer

    DIM objWMIService

    DIM colItems

    DIM strCount

    DIM objitem

    DIM stripaddress

    DIM IP

    TAB  = CHR( 9 )

    CRLF = CHR( 13 ) & CHR( 10 )

    strcomputer = "."

    Set objWMIService = GetObject("winmgmts:" _

       & "{impersonationLevel=impersonate}!\" & strComputer & "rootcimv2")

    Set colItems = objWMIService.ExecQuery _

       ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")

    strCount = 1

    For Each objitem in colitems

       If strCount = 1 Then

           strIPAddress = Join(objitem.IPAddress, ",")

           IP = stripaddress

           strCount = strCount + 1

            ‘ wscript.echo IP

       Else

       End If

    next

    IF WScript.Arguments.Length = 1 THEN

       strServer = WScript.Arguments( 0 )

    ELSE

       strServer = "localhost"

    END IF

    WScript.Echo "Enumerating websites on " & strServer & CRLF

    SET objWebService = GetObject( "IIS://" & strServer & "/W3SVC" )

    EnumWebsites objWebService

    SUB EnumWebsites( objWebService )

       DIM objWebServer, strBindings

       FOR EACH objWebServer IN objWebService

           IF objWebserver.Class = "IIsWebServer" THEN

               WScript.Echo _

                   IP & TAB & objWebserver.Name & TAB &objWebServer.ServerComment & TAB & State2Desc( objWebserver.ServerState )

               ‘ Enumerate the HTTP bindings (ServerBindings) and

               ‘ SSL bindings (SecureBindings)

               strBindings = EnumBindings( objWebServer.ServerBindings ) & EnumBindings( objWebServer.SecureBindings )

               IF NOT strBindings = "" THEN

                   ‘ WScript.Echo strBindings

               END IF

           END IF

       NEXT

    END SUB

    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 & TAB

               EnumBindings = EnumBindings & _

                              strIP & TAB & _

                              strPort & TAB & _

                              strHost & TAB & _

                              ""

           NEXT

           EnumBindings = EnumBindings & CRLF

       NEXT

    END FUNCTION

    FUNCTION State2Desc( nState )

       SELECT CASE nState

       CASE 1

           State2Desc = "Starting (MD_SERVER_STATE_STARTING)"

       CASE 2

           State2Desc = "Started (MD_SERVER_STATE_STARTED)"

       CASE 3

           State2Desc = "Stopping (MD_SERVER_STATE_STOPPING)"

       CASE 4

           State2Desc = "Stopped (MD_SERVER_STATE_STOPPED)"

       CASE 5

           State2Desc = "Pausing (MD_SERVER_STATE_PAUSING)"

       CASE 6

           State2Desc = "Paused (MD_SERVER_STATE_PAUSED)"

       CASE 7

           State2Desc = "Continuing (MD_SERVER_STATE_CONTINUING)"

       CASE ELSE

           State2Desc = "Unknown state"

       END SELECT

    END FUNCTION

    My question, and i’ve searched high and low.   How do i grab the header names from under "website properties > website tab > Advanced button > Host Headers?

    I can’t find anything in how to grab that.  We are consolidating our "similar sites" and the current incarnation of the script doesn’t show the host headers on the sites we combined into one site.

  69. Brian says:

    Nevermind.. lol   in the modified script i made i inadvertantly took that part out..

    nothing to see, move along… 🙂

  70. Gil says:

    Thanks for the script! Is there any way that I can receive the IP address of the IIS Server that is currently being used on my website? I have 2 IIs servers for the website and I’d like to know which was used when a user registers (a record is inserted  to the db) on my website.

  71. RoarBoy says:

    David, thank you so much.

    We used the basis of your script to deploy to over 1K+ web servers as ASP page – this allows us to target a specific page in any web site and it will obviously provide us with the info for all hosted applications – made life so much simpler for us…

    i.e. server name, web site names, State, IP’s, etc etc…

    Our code is below:

    1.) Anonymous Authetication must be disabled on this asp file

    2.) Integrated Windows Authentication must be enabled on this asp file.

    — Start of Code —

    <%@LANGUAGE=VBSCRIPT

    @ENABLESESSIONSTATE=False%>

    <% Option Explicit %>

    <% Response.Buffer=True %>

    <% Response.Expires=0 %>

    <% Response.ExpiresAbsolute=Date-1%>

    <% Response.AddHeader "cache-control","private"%>

    <% Response.AddHeader "pragma","no-cache"%>

    <%

    ‘——- WWWinfo.asp script to obtain Server & WWW information ——-

    ‘——- obtain Server Name ——-

    Dim objNetwork

    Dim strServer

    Set objNetwork = CreateObject("WScript.Network")

    strServer = UCase(objNetwork.ComputerName)

    Set objNetwork = Nothing

    %>

    <table border="0" align="center" width="90%" style="font-family: Verdana; font-size: 12pt" >

    <tr>

     <td align="center" colspan="9" background="./canvas.jpg"><img src="./logo.gif"></td>

    </tr>

    <tr>

     <td bgcolor="#6699FF" align="center" colspan="9"><font color="#FFFFFF"><b>WEB SERVER : <% Response.Write UCase(strServer) %></b></font></td>      

    </tr>

    <tr>

     <td align="center"><font size="1"><b>Site ID</b></font></td>

     <td align="center"><font size="1"><b>Description</b></font></td>

     <td align="center"><font size="1"><b>Site Dir</b></font></td>

     <td align="center"><font size="1"><b>Log Dir</b></font></td>

     <td align="center"><font size="1"><b>IP Address</b></font></td>

     <td align="center"><font size="1"><b>TCP Port</b></font></td>

     <td align="center"><font size="1"><b>SSL Port</b></font></td>

     <td align="center"><font size="1"><b>Status</b></font></td>

    </tr>

    <%

    ‘——- obtain Server Name ——-

    DIM CRLF, TAB

    ‘DIM strServer

    DIM objWebService

    DIM objWebServerRoot

    TAB  = CHR( 9 )

    CRLF = CHR( 13 ) & CHR( 10 )

    ‘Response.Write "Enumerating websites on " & strServer & CRLF

    SET objWebService = GetObject( "IIS://" & strServer & "/W3SVC" )

    EnumWebSites objWebService

    SUB EnumWebSites( objWebService )

       DIM objWebServer, strBindings

       FOR EACH objWebServer IN objWebService

           IF objWebserver.Class = "IIsWebServer" THEN

    SET objWebServerRoot = getobject(objWebServer.adspath & "/root")

    %>

    <tr>

     <td align="center"><font size="1"><% Response.Write "W3SVC" & (objWebserver.Name) %></font></td>

     <td align="center"><font size="1"><% Response.Write (objWebServer.ServerComment) %></font></td>

     <td align="center"><font size="1"><% Response.Write (objWebserverRoot.Path) %></font></td>

     <td align="center"><font size="1"><% Response.Write (objWebServer.LogFileDirectory & "W3SVC" & objWebserver.Name) %></font></td>

     <td align="center"><font size="1"><% Response.Write (EnumIP (objWebServer.ServerBindings)) %></font></td>

     <td align="center"><font size="1"><% Response.Write (EnumSrvPort (objWebServer.ServerBindings)) %></font></td>

     <td align="center"><font size="1"><% Response.Write (EnumSrvPort (objWebServer.SecureBindings)) %></font></td>

     <td align="center"><font size="1"><% Response.Write (State2Desc( objWebserver.ServerState )) %></font></td>

    <%

    ‘——- Enumerate Bindings ——-

               strBindings = EnumBindings( objWebServer.ServerBindings ) & _

                             EnumBindings( objWebServer.SecureBindings )

               IF NOT strBindings = "" THEN

               END IF

           END IF

    set objWebServerRoot=nothing

       NEXT

    END SUB

    ‘——- Strip IP Bindings ——-

    FUNCTION EnumIP( objBindingList )

       DIM x, strIP

       DIM reBinding, reMatch, reMatches

       SET reBinding = NEW RegExp

       reBinding.Pattern = "([^:]*):([^:]*):(.*)"

       FOR x = LBOUND( objBindingList ) TO UBOUND( objBindingList)

           SET reMatches = reBinding.Execute( objBindingList( x ) )

           FOR EACH reMatch IN reMatches

               strIP = reMatch.SubMatches( 0 )

               IF strIP = "" THEN strIP = "All Unassigned"

               IF LEN( strIP ) < 8 THEN strIP = strIP & TAB

               EnumIP = EnumIP & strIP

           NEXT

           EnumIP = EnumIP & CRLF

       NEXT

    END FUNCTION

    ‘——- Strip PORT Bindings ——-

    FUNCTION EnumSrvPort( objBindingList )

       DIM y, strPort

       DIM reBinding, reMatch, reMatches

       SET reBinding = NEW RegExp

       reBinding.Pattern = "([^:]*):([^:]*):(.*)"

       FOR y = LBOUND( objBindingList ) TO UBOUND( objBindingList )

           SET reMatches = reBinding.Execute( objBindingList( y ) )

           FOR EACH reMatch IN reMatches

               strPort = reMatch.SubMatches( 1 )

               IF strPort = "" THEN strPort = "*"

               EnumSrvPort = EnumSrvPort & strPort

           NEXT

           EnumSrvPort = EnumSrvPort & CRLF

       NEXT

    END FUNCTION

    ‘——- Strip HOST Bindings ——-

    FUNCTION EnumBindings( objBindingList )

       DIM z, strIP, strPORT, strHost

       DIM reBinding, reMatch, reMatches

       SET reBinding = NEW RegExp

       reBinding.Pattern = "([^:]*):([^:]*):(.*)"

       FOR z = LBOUND( objBindingList ) TO UBOUND( objBindingList )

           ‘ objBindingList( i ) is a string looking like IP:Port:Host

           SET reMatches = reBinding.Execute( objBindingList( z ) )

           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 & TAB

               EnumBindings = EnumBindings & _

                              strIP & TAB & _

                              strPort & TAB & _

                              strHost & TAB & _

                              ""

           NEXT

           EnumBindings = EnumBindings & CRLF

       NEXT

    END FUNCTION

    ‘——- DEFINE IIS STATUS ——-

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

       END SELECT

    END FUNCTION

    %>

    — End of Code —

  72. Tim says:

    Wow, talk about doing things the hard way.  A few tips, David (if you haven’t figured these out in the past four years):

    vbTab is a VB constant – you don’t need TAB

    vbCrLf is a VB constant – you don’t need CRLF

    If Not strBindings = "" Then   … is easier said: If strBindings <> "" Then

    That reBinding regular expression isn’t needed.. try Split(objBindingList(i),":") … results in an array as well but more efficient and less confusing

    Adding & "" to the end of the EnumBindings = EnumBindings.. statement is pointless

    Otherwise, nice job on a working prototype.

  73. Sukhi says:

    David, Please share the script which should display the home folder path along with full information about the Virtual Directories configured in the website as well.

    This script is also not displaying the Application pool configured for the website.

  74. zagadeesh says:

    ‘  Enumerate Servers in the domain, which is having IIS

    ‘  Same code given by DAVID

    ‘  Can you please evaluate

    ‘  ———————————————————

    Set objAdRootDSE = GetObject("LDAP://RootDSE")

    Set objRS = CreateObject("adodb.recordset")

    Set objFSO = CreateObject("Scripting.FileSystemObject")

    Set objFile = objFSO.CreateTextFile("./IIS_Site_list.txt",2)

    Set WshNetwork = WScript.CreateObject("WScript.Network")

    strLhost = WshNetwork.ComputerName

     varConfigNC = objAdRootDSE.Get("defaultNamingContext")

     strConnstring = "Provider=ADsDSOObject"

     strWQL = "SELECT * FROM ‘LDAP://" & varConfigNC & "’ WHERE objectCategory= ‘Computer’ and OperatingSystem = ‘Windows*Server*’"

     objRS.Open strWQL, strConnstring

     Do until objRS.eof

    ‘WSCRIPT.ECHO "tEST"

    Set objServer = GetObject(objRS.Fields.Item(0))

    strServerName = objServer.CN

    strOperatingSystem = objServer.OperatingSystem

    Set cPingResults = GetObject("winmgmts:{impersonationLevel=impersonate}//" & _

    strLhost & "/root/cimv2"). ExecQuery("SELECT * FROM Win32_PingStatus " & _

    "WHERE Address = ‘" + strServerName + "’")

    For Each oPingResult In cPingResults

    If oPingResult.StatusCode = 0 Then

    objfile.write strServerName & " is running " & strOperatingSystem & " Reachable"

    Set objWMIService = GetObject("winmgmts:\" & strservername & "rootcimv2")

    Set colServices = objWMIService.ExecQuery ("Select * from Win32_Service where Name Like ‘%IIS%’")

    IF colServices.Count = 0 Then

    objFile.Write ",IIS is not installed."

    objfile.writeline

    Else

    SET objWebService = GetObject( "IIS://" & strServername & "/W3SVC" )

    FOR EACH objWebServer IN objWebService

    IF objWebserver.Class = "IIsWebServer" THEN

               objFile.write "," & objWebserver.Name & "," & objWebServer.ServerComment & "," & _

               State2Desc( objWebserver.ServerState ) & "," & objWebServer.LogFileDirectory

                strBindings = EnumBindings( objWebServer.ServerBindings ) & _

                              EnumBindings( objWebServer.SecureBindings )

                IF NOT strBindings = "" THEN

                    objFile.Write( strBindings )

                END IF

    objfile.writeline

            END IF

        NEXT

    ‘objFile.WriteLine ‘(strText)

    End If

    Else

    objFile.writeLine strServerName & " is running " & strOperatingSystem & " NOT Reachable"

    ‘objfile.Writeline

    end if

    Next

    objRS.movenext

    Set objServer = Nothing

       Loop

     objRS.close

    Set objRS = Nothing

    Set objAdRootDSE = Nothing

    wscript.echo "Mission accomplished…"

    ‘————————————————————–

    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 & TAB

               EnumBindings = EnumBindings & "," & _

                              strIP & "," & _

                              strPort & "," & _

                              strHost & "," & _

                              ""

           NEXT

           EnumBindings = EnumBindings & CRLF

       NEXT

    END FUNCTION

    FUNCTION State2Desc( nState )

       SELECT CASE nState

       CASE 1

           State2Desc = "Starting (MD_SERVER_STATE_STARTING)"

       CASE 2

           State2Desc = "Started (MD_SERVER_STATE_STARTED)"

       CASE 3

           State2Desc = "Stopping (MD_SERVER_STATE_STOPPING)"

       CASE 4

           State2Desc = "Stopped (MD_SERVER_STATE_STOPPED)"

       CASE 5

           State2Desc = "Pausing (MD_SERVER_STATE_PAUSING)"

       CASE 6

           State2Desc = "Paused (MD_SERVER_STATE_PAUSED)"

       CASE 7

           State2Desc = "Continuing (MD_SERVER_STATE_CONTINUING)"

       CASE ELSE

           State2Desc = "Unknown state"

       END SELECT

    END FUNCTION

  75. zagadeesh says:

    David & all,

    I have 2000+ servers, need to know which servers are having IIS.

    I used above script. But

    When it reached to

    Set colServices = objWMIService.ExecQuery ("Select * from Win32_Service where Name Like ‘%IIS%’")

    few server are not responding for even 24 hours so I modified that line like following (added ,,48)

    Set colServices = objWMIService.ExecQuery ("Select * from Win32_Service where Name Like ‘%IIS%’",,48)

    Further I got a issue at

    SET objWebService = GetObject( "IIS://" & strServername & "/W3SVC" )

    not progressing at above line, got the following error…

    support007.vbs(xx, x) Microsoft VBScript runtime error: ActiveX component can’t create object: ‘GetObject’

    thanks

  76. WMI? says:

    Is it possible to do this with WMI???

  77. Jagadeesh_v01 says:

    Hello David,

    I want a VB Script for the "installer has to verify if the website is configured for https. if not it should appear dialog box saying that website is not configured".

    Thanks In Advance.

    Regards,

    Jagadeesh