Chris Crowe's Blog
Ramblings of an IIS MVP ( MVP Since 1997 )

Powered By IIS 7

Search my blog

Some of my readers



My Microsoft Certifications


Dec 15, 1998

Dec 20, 2000

Jan 31, 2001

Jul 22, 2002

Nov 1, 2004

My Microsoft MVP Awards




1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
mvp.support.microsoft.com

December 2005 Entries

This script will show you each Web Site ID and the description and the bindings that they are using.

Save the script to a file with a .VBS file extension and then run using this command:

cscript  MyFile.VBS

MachineName = "localhost"
IIsObjectPath = "IIS://" & MachineName & "/w3svc"


Set IIsObject = GetObject(IIsObjectPath)
for each obj in IISObject
if (Obj.Class = "IIsWebServer") then
BindingPath = IIsObjectPath & "/" & Obj.Name

Set IIsObjectIP = GetObject(BindingPath)
wScript.Echo IISObjectIP.ServerComment & " ( W3SVC" & obj.Name & " ) "

ValueList = IISObjectIP.Get("ServerBindings")
ValueString = ""
For ValueIndex = 0 To UBound(ValueList)
value = ValueList(ValueIndex)
Values = split(value, ":")
IP = values(0)
if (IP = "") then
IP = "(All Unassigned)"
end if
TCP = values(1)
if (TCP = "") then
TCP = "80"
end if
HostHeader = values(2)

if (HostHeader <> "") then
wScript.Echo " IP = " & IP & " TCP/IP Port = " & TCP & ", HostHeader = " & HostHeader
else
wScript.Echo " IP = " & IP & " TCP/IP Port = " & TCP
end if
Next
wScript.Echo ""
set IISObjectIP = Nothing
end if
next
set IISObject = Nothing

Example Output

Default Web Site ( W3SVC1 )
IP = 10.1.1.11 TCP/IP Port = 80

WebSite1 ( W3SVC1036328378 )
IP = 10.1.1.74 TCP/IP Port = 80

WebSite2 ( W3SVC1816184000 )
IP = 10.1.1.73 TCP/IP Port = 80

WebSite3 ( W3SVC1867813904 )
IP = 10.1.1.72 TCP/IP Port = 80

WebSite4 ( W3SVC568530179 )
IP = 10.1.1.71 TCP/IP Port = 80

WebSite5 ( W3SVC719499532 )
IP = 10.1.1.70 TCP/IP Port = 80

WebSite6 ( W3SVC669732006 )
IP = (All Unassigned) TCP/IP Port = 81
 

 

This script will show you the W3SVC Web Site ID and the description.

With IIS 6 the Web Site ID is a randomly generated number for each site that is created other than the Default Web Site which has an Web Site ID of 1)

For example:

W3SVC1
W3SVC719499532
W3SVC383732556

Knowing which web site these being to is a problem as it requires you to manually look at each web site. The following script will allow you to output the ID and name.

Save the script to a file with a .VBS file extension and then run using this command:

cscript  MyFile.VBS

Function ProcessWebSite(ServiceType, SiteNumber)
Set IISWebSite = getObject("IIS://localhost/" & ServiceType & "/" & SiteNumber)
Set IISWebSiteRoot = getObject("IIS://localhost/" & ServiceType & "/" & SiteNumber & "/root")
ProcessWebSite = IISWebSite.ServerComment
Set IISWebSiteRoot = nothing
Set IISWebSite = Nothing
end function

Function ShowSites(ServiceType, ClassName, Title)
Wscript.echo "Web Sites Description"
Wscript.echo "==============================================================="
Set IISOBJ = getObject("IIS://localhost/" & ServiceType)
for each Web in IISOBJ
if (Web.Class = ClassName) then
wscript.echo Ucase(ServiceType) & "/" & Web.Name & _
Space(17-(len(Ucase(ServiceType))+1+len(Web.Name))) & " " & _
ProcessWebSite(ServiceType, Web.name)
end if
next
Set IISOBj=Nothing
WScript.Echo ""
End function

Call ShowSites("w3svc", "IIsWebServer", "Web")

The output from this is similar to the following:

Web Sites                    Description
===============================================================
W3SVC/1                   Default Web Site
W3SVC/1036328378 WebSite1
W3SVC/1816184000 WebSite2
W3SVC/1867813904 WebSite3
W3SVC/568530179   WebSite4
W3SVC/719499532   WebSite5
W3SVC/669732006   WebSite6