Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's what I came up with:</p> <pre><code>@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" </code></pre> <p>The command outputs a list of virtual directory ID's, along with the "friendly name" and path for each, e.g.:</p> <pre><code>/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" </code></pre> <p>If you want to pipe the output to a text file, first make sure it doesn't exist, then append <code>&gt;&gt; filename.txt</code> to the command above. (e.g.: <code>DEL sites.txt &amp; ... &gt;&gt; sites.txt</code>)</p> <p>Here's a breakdown of how the admittedly convoluted command works:</p> <ol> <li><p><code>@</code> is prefixed to every statement to avoid echoing the statement itself, which would pollute the output.</p></li> <li><p><code>@FOR /F "delims=[]" %A IN ('@cscript //nologo %SystemDrive%\Inetpub\AdminScripts\adsutil.vbs ENUM /P /w3svc') DO</code></p> <p>Invokes <a href="https://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/d3df4bc9-0954-459a-b5e6-7a8bc462960c.mspx?mfr=true" rel="nofollow noreferrer">AdsUtil.vbs</a>, which is installed with IIS6 (and reads the <a href="http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/a0ea8e51-fb2a-4e80-9d5a-7fe3ae246570.mspx?mfr=true" rel="nofollow noreferrer">metabase</a> on our behalf).</p> <ul> <li>The <code>ENUM /P /w3svc</code> parameter tells it to spit out a list of all sites and virtual directory ID's starting at the root node.</li> <li>The <a href="http://msdn.microsoft.com/en-us/library/ms525006%28v=vs.90%29.aspx" rel="nofollow noreferrer">nologo</a> 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.</li> <li><p>The output of the portion in single quotes resembles the following:</p> <pre><code>[/w3svc/1] [/w3svc/1236224994] [/w3svc/1359392326] [/w3svc/1835917338] [/w3svc/198968327] [/w3svc/AppPools] [/w3svc/Filters] [/w3svc/Info] </code></pre></li> </ul> <p>This is passed into <code>FOR /F</code>, which loops through each line. <code>delims=[]</code> tells FOR to treat square brackets as delimiters. Everything after the <code>DO</code> will be executed once for each line, with the <code>%A</code> variable set to whatever is between the square brackets. (If this was a batch file you'd use <code>%%A</code> instead).</p></li> <li><p><code>@FOR /F delims^=^"^ tokens^=2 %B IN ('@cscript //nologo %SystemDrive%\Inetpub\AdminScripts\adsutil.vbs //nologo GET %A/ServerComment') DO</code></p> <p>This second FOR block runs AdsUtil with the <code>GET</code> 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 <code>/w3svc/1</code> you get back:</p> <pre><code>ServerComment : (STRING) "Default Web Site" </code></pre> <p>The <a href="https://stackoverflow.com/a/13217838/589059">careting trick</a> parses out the text between the quotes.</p> <p>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.:</p> <pre><code>The path requested could not be found. ErrNumber: -2147024893 (0x80070003) Error Trying To GET the Object (GetObject Failed): w3svc/Filters </code></pre> <p>Thus the remaining portion of the command line is not invoked for them.</p></li> <li><p><code>@FOR /F delims^=^"^ tokens^=2 %C IN ('@cscript %SystemDrive%\Inetpub\AdminScripts\adsutil.vbs //nologo GET %A/Root/Path') DO @ECHO %A %B "%C"</code></p> <p>This final FOR retrieves the physical path, then outputs all three pieces of parsed information to the console.</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload