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

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
posted on Thursday, December 08, 2005 4:25 PM | Filed Under [ IIS IIS / Tools / Scripts ]

Comments


# re: Displaying the Web Site ID and the Description


This script just saved me a ton of time. Thanks.
Posted by Tom on 1/10/2008 9:47 AM

# re: Displaying the Web Site ID and the Description

Gravatar
hi

i m using this above vb script code file in my c# code
i am able to extract this file using c# but my problem is i need to return a value i.e webId of particular website given by user and to use that id in my further C# code.
Posted by Nidhika on 12/16/2008 10:00 PM

# re: Displaying the Web Site ID and the Description

Gravatar
Hi Chris, that is very handy. Thanks.
Posted by codemeit on 2/21/2009 10:08 PM

# re: Displaying the Web Site ID and the Description


thank you , just helped me revive my tswa
Posted by Gilad Sapir on 5/15/2009 1:14 AM

# re: Displaying the Web Site ID and the Description

Gravatar
Thank you for the script. This helped with my Security Metrics problem.
Posted by Jim Zaino on 10/9/2009 3:31 AM

Post Comment


Title *
Name *
Email
Url
Comment *  
Please add 4 and 4 and type the answer here: