Displaying the Web Site ID and the Description in IIS

In IIS 6 and later, 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.

Knowing which web site uses which ID requires you to manually look at each of them. The following script will allow you to output the ID and description.


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

cscript MyFile.VBS

Here is the code...

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

...and the result

W3SVC/1           Default Web Site
W3SVC/1013149732  CorporateSite
W3SVC/1468412562  CorporatePortal
W3SVC/1529035351  CorporateMobile
W3SVC/1595630563  redirections



Commentaires