2015-02-11 63 views
0

我有一个几年前写过的vbscript,它列出了具有各种属性的IIS服务器上的所有站点。我一直在试图修改它以列出每个虚拟目录的路径,但“application”和“applicationcollection”似乎都不是site元素的子元素。我浏览了MS文档,但他们的示例代码仅显示添加应用程序,未列出它们。如何使用vbscript枚举IIS虚拟目录

这是我到目前为止:

Set adminManager = Wscript.createObject("Microsoft.ApplicationHost.WritableAdminManager") 
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST" 
Set sitesSection = adminManager.GetAdminSection("system.applicationHost/sites", "MACHINE/WEBROOT/APPHOST") 
Set sitesCollection = sitesSection.Collection 
For siteCount = 0 To CInt(sitesCollection.Count)-1 
    Set siteElement = sitesCollection(siteCount) 

'Various other bits here.... 

'Then this line doesn't work. I can't figure out how to reference the application 
Set appCollection = siteElement.ChildElements.Item("applicationCollection").Collection 
Next 

有人可以发布一些示例vbscript列出该网站的虚拟目录?

+0

http://serverfault.com/questions/107619/how-do-i-get-a-list-of-websites-from-iis-showing-the -host-header-value-descript - 我已经测试过这个Windows 2012 - 它的工作原理。 – Damien 2015-02-12 01:19:21

+0

谢谢,我已经看到过这个脚本,但它有几个问题 - 首先它使用WMI,因此需要安装IIS6 WMI兼容性,这与我正在使用的计算机上不兼容。其次它只列出每个站点的主要路径,而不是其他虚拟目录。 我想使用管理员管理器,就像我在上面的脚本中一样。我可以获得所有其他属性。我只是无法弄清楚如何引用应用程序或虚拟目录。 – Vershner 2015-02-12 10:05:47

回答

0

最终通过非常有用的IIS Configuration Reference得到了帮助。这现在显示“[应用程序]物理路径”

Set siteCollection = siteElement.Collection 
spath = "" 
For appCount = 0 To CInt(siteCollection.Count)-1 
    Set appElement = siteCollection.Item(appCount) 
    Set appCollection = appElement.Collection 
    For vdCount = 0 To CInt(appCollection.Count)-1 
    Set vdElement = appCollection.Item(vdCount) 
    spath = spath & "[" & CStr(appElement.Properties.Item("path").Value) & "] " & CStr(vdElement.Properties.Item("physicalPath").Value) & VbCrLf 
    Next 

Next