DOS命令列出IIS 6中的所有虚拟目录 [英] DOS command to list all virtual directories in IIS 6

查看:1504
本文介绍了DOS命令列出IIS 6中的所有虚拟目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个DOS命令列出IIS 6在Windows 2003下的所有网站和虚拟目录。我知道有办法使用 Powershell / WMI VBS C#等等。但我想要的是一个快速,脏,没有什么方法来做它从DOS,而不需要在Web服务器上创建任何新文件。

I'm looking for a DOS command to list all sites and virtual directories in IIS 6 under Windows 2003. I know there are ways to do this using Powershell / WMI, VBS, C#, etc. But all I want is a quick and dirty, no-fuss way to do it from DOS, without the need to create any new files on the Webserver.

编辑:在研究这个问题时,我设法提出一个单行程序,但请建议一个替代

While researching for this question I managed to come up with a one-liner that does it, but please do suggest an alternative if you have a more elegant solution that fits the criteria above.

推荐答案

以下是我想出的:

@FOR /F "delims=[]" %A IN ('@cscript //nologo %SystemDrive%\Inetpub\AdminScripts\adsutil.vbs ENUM /P /w3svc') DO @FOR /F delims^=^"^ tokens^=2 %B IN ('@cscript //nologo %SystemDrive%\Inetpub\AdminScripts\adsutil.vbs GET %A/ServerComment') DO @FOR /F delims^=^"^ tokens^=2 %C IN ('@cscript %SystemDrive%\Inetpub\AdminScripts\adsutil.vbs //nologo GET %A/Root/Path') DO @ECHO %A %B "%C"

虚拟目录ID,以及每个的友好名称和路径,例如:

The command outputs a list of virtual directory ID's, along with the "friendly name" and path for each, e.g.:

/w3svc/1 Default Web Site "c:\inetpub\wwwroot"
/w3svc/1236224994 FunWidgets "C:\Inetpub\wwwroot\FunWidgets"
/w3svc/1359392326 JimSmith.com "C:\Inetpub\wwwroot\JimSmith"
/w3svc/1835917338 BouncyToys "C:\Inetpub\wwwroot\bouncytoys"
/w3svc/198968327 AvalonWest "C:\Inetpub\wwwroot\AvWest"

如果要将输出传递到文本文件,首先确保它不存在,然后append >> filename.txt 到上面的命令。 (例如: DEL sites.txt& ...>> sites.txt

If you want to pipe the output to a text file, first make sure it doesn't exist, then append >> filename.txt to the command above. (e.g.: DEL sites.txt & ... >> sites.txt)

细节如何令人信服的复杂命令的工作原理:

Here's a breakdown of how the admittedly convoluted command works:


  1. @

@FOR / Fdelims = [] %A IN('@cscript // nologo%SystemDrive%\Inetpub\AdminScripts\adsutil.vbs ENUM / P / w3svc')DO

调用 AdsUtil.vbs ,它随IIS6安装(并读取 metabase 代表我们)。

Invokes AdsUtil.vbs, which is installed with IIS6 (and reads the metabase on our behalf).


  • code> ENUM / P / w3svc 参数指示它从根节点开始列出所有网站和虚拟目录ID。

  • nologo 开关抑制了常见的CScript版权前缀,只渲染我们感兴趣的输出。双反斜杠用于转义斜杠字符,因为我们在字符串内。

  • 输出单引号中的部分类似于以下内容:

  • The ENUM /P /w3svc parameter tells it to spit out a list of all sites and virtual directory ID's starting at the root node.
  • The nologo switch suppresses the usual CScript copyright preamble, to render only the output we're interested in. A double-backslash is used to escape the slash character, since we're inside a string.
  • The output of the portion in single quotes resembles the following:

[/w3svc/1]
[/w3svc/1236224994]
[/w3svc/1359392326]
[/w3svc/1835917338]
[/w3svc/198968327]
[/w3svc/AppPools]
[/w3svc/Filters]
[/w3svc/Info]


这被传递到 FOR / F ,它循环遍历每一行。 delims = [] 指示FOR将方括号视为分隔符。 DO 之后的所有内容将对每行执行一次,将%A 变量设置为正方形括号。 (如果这是批处理文件,则改为使用 %% A )。

This is passed into FOR /F, which loops through each line. delims=[] tells FOR to treat square brackets as delimiters. Everything after the DO will be executed once for each line, with the %A variable set to whatever is between the square brackets. (If this was a batch file you'd use %%A instead).

@FOR / F delims ^ = ^^ tokens ^ = 2%B IN('@cscript // nologo%SystemDrive%\Inetpub\AdminScripts\adsutil.vbs // nologo GET%A / ServerComment ')DO

此第二个FOR块运行AdsUtil与 GET 参数检索对于 / w3svc / 1 您回来:

This second FOR block runs AdsUtil with the GET parameter to retrieve the ServerComment property for the given site / virtual directory. This is the human-friendly name as seen in IIS. Unfortunately the output is a bit trickier to parse. e.g. For /w3svc/1 you get back:

ServerComment                   : (STRING) "Default Web Site"

看护诀窍解析文字

请注意,我们不感兴趣的节点(AppPools,Filters和Info)没有ServerComment属性,并且给出的结果没有引号,例如:

Note that nodes we aren't interested (AppPools, Filters and Info) don't have the ServerComment property, and give a result devoid of quotes, e.g.:

The path requested could not be found.
ErrNumber: -2147024893 (0x80070003)
Error Trying To GET the Object (GetObject Failed): w3svc/Filters

因此,命令行的其余部分不会为其调用。

Thus the remaining portion of the command line is not invoked for them.

@FOR / F delims ^ = ^^ tokens ^ = 2%C IN('@cscript%SystemDrive%\Inetpub\AdminScripts\adsutil.vbs // nologo GET%A / Root / Path')DO @ECHO%A%B %C

这最后一个FOR检索物理路径,然后将所有三个解析的信息输出到控制台。

This final FOR retrieves the physical path, then outputs all three pieces of parsed information to the console.

这篇关于DOS命令列出IIS 6中的所有虚拟目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆