VBScript: IIS Discovery
Find IIS Servers on your domain (or with modifications, your subnet) using this script
Note (2025): This is an archival VBScript from 2006 that relies on legacy technologies (ADSI and MSXML HTTP) and domain browsing via the WinNT provider. VBScript and these approaches are considered legacy on modern Windows and may be disabled by default in many environments. For modern automation, prefer PowerShell and the IIS WebAdministration module or remote management APIs. The script below is preserved for historical reference.
1'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Author: Chrissy LeMaire ' Copyright 2003 NetNerds Consulting Group ' Script is provided AS IS with no warranties or guarantees and assumes no liabilities. ' Website: https://www.netnerds.net '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' On Error Resume Next
2
3theDomain = "mydomain" ' set this here if you are probing a different domain
4
5Set objNet = CreateObject("WScript.Network") myFullUsername = trim(objNet.Userdomain & "" & objNet.UserName) myComputerName = trim(objNet.ComputerName)
6
7if len(theDomain) = 0 then theDomain = Trim(objNet.Userdomain) end if myUsername = Trim(objNet.UserName) set objNet = nothing
8
9'in case the groups below do not exist
10
11ADMIN = FALSE Set objGroup = GetObject("WinNT://" & theDomain & "/Domain Admins") For Each objUser in objGroup.Members If LCase(myusername) = LCase(objUser.Name) Then ADMIN = TRUE End If Next Set objGroup = Nothing
12
13Set objGroup = GetObject("WinNT://" & theDomain & "/Enterprise Admins") For Each objUser in objGroup.Members If LCase(myusername) = LCase(objUser.Name) Then ADMIN = TRUE End If Next Set objGroup = Nothing
14
15IIS = FALSE err.Clear ' to clear any possible errors from above
16
17Set objW3SVC = GetObject("IIS://" & myComputerName & "/W3SVC") if err.Number = 0 Then IIS = TRUE end If
18
19if ADMIN = FALSE Then MsgBox "You are not a Domain administrator. This script will not work properly." Wscript.Quit End If
20
21if IIS = FALSE Then MsgBox "IIS is not installed. This script will not work properly." Wscript.Quit End If set objW3SVC = Nothing
22
23on error goto 0
24
25startTime = Timer()
26
27'Use the WinNT Directory Services theDomain = "WinNT://" & theDomain 'Create the Domain object Set objDomain = GetObject(theDomain) 'Search for Computers in the Domain objDomain.Filter = Array("Computer")
28
29On error resume next serverCount = 0 IISServerCount = 0
30
31For Each Computer In objDomain theServer = Computer.Name serverCount = ServerCount + 1 Set objW3SVC = GetObject("IIS://" & theServer & "/W3SVC") Select Case Err.Number ' 70 = permission denied; Strong indication of IIS Server in a DMZ ' 462 = The remote server machine does not exist or is unavailable ' 429 = ActiveX component can't create object ' -2147023169 = CreateObject Failed ' -2147012889 = Name could not be resolved case 462, 429 thehttpVersion = cint(httpVersion(theServer)) if thehttpVersion > 0 and thehttpVersion < 404 then IISServerCount = IISServerCount + 1 IISTrue = IISTrue & "IIS Server: " & theServer & VbCrLf else IISFalse = IISFalse & "NOT: " & theServer & VbCrLf end if case 70,-2147023169,-2147012889 IISUnknown = IISUnknown & "Possibly: " & theServer & VbCrLf case 0,-2146646000 IISServerCount = IISServerCount + 1 IISTrue = IISTrue & "IIS Server: " & theServer & VbCrLf set objW3SVC = Nothing case else 'wscript.echo theServer & ": " & errNumber & ", " & err.Description & "
32
33" ' for debugging end Select
34
35Err.Clear Next Set objDomain = Nothing
36
37Function httpVersion(theHost) On Error Resume Next Set objxmlHTTP = createobject("MSXML2.ServerxmlHTTP") theURL= "https://" & theHost objxmlHTTP.open "GET", theURL, false objxmlHTTP.send() tempVersion = objxmlHTTP.getResponseHeader("Server") If errNumber = -2147012867 Then NOSERVER = TRUE Else NOSERVER = FALSE End If set objxmlHTTP = nothing
38
39If instr(tempversion,"Microsoft-IIS/") > 0 then tempVersion = replace(tempVersion,"Microsoft-IIS/","") httpVersion = trim(tempVersion) else if NOSERVER = TRUE then httpVersion = "404" ' webserver not found ;) err.Clear Else 'there was a webserver there, but probably not an IIS Server httpVersion = "0" End If End If End Function
40
41finishtime = Timer() totalTime = finishtime - startTime
42
43myStr = myStr & "Total Time Taken: " & totalTime & " seconds" & vbCrLf & vbCrLf myStr = myStr & "Total Servers Scanned: " & serverCount & vbCrLf myStr = myStr & "Total Servers Found: " & IISServerCount & vbCrLf & vbCrLf myStr = myStr & IISTrue & vbCrLf myStr = myStr & IISUnknown & vbCrLf 'myStr = myStr & IISFalse & vbCrLf myStr = myStr & "Done" & vbCrLf
44
45wscript.echo myStr
Requirements: A Windows Domain, local IIS install, domain administrator rights.