How To: Using IIS 6.0 Command Line Utilities - Part 2

Continuing my last post on using Command line utilities with IIS 6.0 I will now be discussing on how to use some of those command which can make our life as an IIS admin happy!

Lets start with adsutil.vbs

Working with adsutil.vbs is fairly simple once you get to know how is accepts commands. To know the procedure you must understand the flow of Metabase.xml

Let's start with this easy and short command...
>cscript.exe %systemdrive%\inetpub\adminscripts\adsutil.vbs enum w3svc /P
You will get a reply similar to this:

[/w3svc/1]
[/w3svc/AppPools]
[/w3svc/Filters]
[/w3svc/Info]

We have just enumerated the paths for w3svc by using the /P switch. In my case you see /w3svc/1 as I am running with just the default website. But you would see similar entries of /w3svc/Website_identifier format, if one had more websites. If you want to enum the complete data as well just remove the /P and run the same command.You will loads more data
Even better:
>cscript.exe %systemdrive%\inetpub\adminscripts\adsutil.vbs enum_all w3svc
Huge information right! That just enumerated the entire w3svc for us. Run this command to get the output page by page wise so that we can actually read it this time ;)
>cscript.exe %systemdrive%\inetpub\adminscripts\adsutil.vbs enum_all w3svc | more
Press space bar to view the next page. Anyways this was just something to get us warmed up!
Now lets get something that we might need. I am going to be taking scenario wise.

Scenario 1:
You need to ENUMERATE a few basic settings of your Default Web Site. Here's how you do it:
>cscript.exe %systemdrive%\inetpub\adminscripts\adsutil.vbs enum w3svc/1/
This is will give you a very basic overview of your website. Technically, the previous command will enum all the parameters within the location w3svc/1/ for the Key type IISWebServer with Website Identifier 1 from the In-Memory Metabase.xml. So if you would want to have a look at another site just replace the ID of that site.

Scenario 2:
You need to GET a particular property of your website. Let us consider we need to know the physical path of a directory named test under Default Web Site. Here's how you do it:
>cscript.exe %systemdrive%\inetpub\adminscripts\adsutil.vbs get w3svc/1/test/path
The only thing to get here is that you would need to mention the directory name(test), followed by the object(path) you wish to find.

Scenario 3:
You need to SET new bindings on your Default Web Site. Here is how you do that:
>cscript.exe %systemdrive%\inetpub\adminscripts\adsutil.vbs set w3svc/1/ServerBindings ":81:"
This will set your Website Server Bindings to port 81. Simple enough right!
To save all of the burden of reading long articles let me end adsutil.vbs here. To be honest this was pretty introductory stuff with adsutil.vbs

iisweb.vbs

This is a very useful utility if you want to create, delete or operate upon the status parameters of an IIS website. iisweb comes in very handy when you want to view basic settings and status of a website running within your network. Run this command
>iisweb /query "Default Web Site"
The above command will tell you the current status, bindings with the name of the web site. You can also put together varioius website running on the same server to get a cumulative information. iisweb commands can run on your remote IIS machines.


iisvdir.vbs

A useful utility to create delete and query virtual web directory on IIS 6 machine. To learn more about the difference about a virtual directory and appplication within IIS check my previous post. You can operate iisvdir command on remote IIS machines as well.
>iisvdir /s Server1 /u "username" /p "password" /create "New Vdirectory" Mydir "Physical Path"
Here is a sample script that is going to create a website for us: Copy paste the following and name it as site.bat.
Run site /? for help. Enjoy!

@IF ?%_ECHO%?==?? ECHO OFF
rem This script will create, start, and give us the status using IIS commmand line utilities
rem Written by MA Khan, http://www.iisworkstation.com
SETLOCAL
SET WEBNAME=%1
SET IP=%2
SET PORT=%3
SET SITE_PATH=%4
SET WEB_CREATE=iisweb

rem Provide Help!

IF /I ?"%WEBNAME%"? EQU ?"HELP"? GOTO :Help
SET NEED_HELP=%WEBNAME:?=%
IF /I ?"%NEED_HELP%"? NEQ ?"%WEBNAME%"? GOTO :Help

rem start execution

:menu
ECHO.
ECHO.
ECHO Website creation script by MA Khan
ECHO Version 1.0 BETA 1
ECHO.
ECHO -------------------------------------------------------------------------------
ECHO --^>This script is going to create, start and give us details on the website that we create.
ECHO --^>Website is going to be created by using %WEB_CREATE%
ECHO -------------------------------------------------------------------------------
ECHO.
ECHO.
rem Start the actual work
rem input validation
ECHO Starting input validation...
IF /I ?%IP%? EQU ?? ( ECHO.&ECHO Validation Failed!&Echo.&Echo Check help for the syntax&GOTO :Help)
IF /I ?%PORT%? EQU ?? ( ECHO.&ECHO Validation Failed!&Echo.&Echo Check help for the syntax&GOTO :Help)
IF /I ?%SITE_PATH%? EQU ?? ( ECHO.&ECHO Validation Failed!&Echo.&Echo Check help for the syntax&GOTO :Help)
IF NOT EXIST "%SITE_PATH%" (
ECHO.
ECHO ERROR: Site physical path is not found!
ECHO Please Specify the right address
GOTO :EOF
)

ECHO Validation Succeeded...
ECHO.
ECHO Details given:
ECHO Website Name: %WEBNAME%
ECHO IP: %IP%
ECHO PORT: %PORT%
ECHO SIte Physical Path: %SITE_PATH%
ECHO.
SET CONFIRM=
SET /P CONFIRM=Type EDIT to edit choices or hit ENTER to proceed:
IF ?%CONFIRM%? EQU ?? GOTO :Create

ECHO.
ECHO Press ENTER to accept [%WEBNAME%], or provide new value (Web Site Name)
SET /P WEBNAME=Web Site Name:
ECHO Press ENTER to accept [%IP%], or provide new value (IPV4 Addres only)
SET /P IP=IP V4 only:
ECHO Press ENTER to accept [%PORT%], or provide new value (Port Number)
SET /P PORT=Port Number:
ECHO Press ENTER to accept [%SITE_PATH%], or provide new value (Physical Path of your website)
SET /P SITE_PATH=Physical Path:

ECHO ---------------------------------------------------------------------------
ECHO Restarting with fresh Values
ECHO ---------------------------------------------------------------------------

GOTO :Menu
GOTO :EOF


:Create
ECHO Starting the website creation...
ECHO.
iisweb /create %SITE_PATH% "%WEBNAME%" /i %IP% /b %PORT%
ECHO.
iisweb /query %WEBNAME%
ECHO.
ECHO We are good to go
GOTO :EOF

:Help
ECHO.
ECHO HELP:
ECHO.
ECHO Syntax:
ECHO site [websitename][ipaddress][port][physical path]
ECHO.
ECHO Description:
ECHO This script is going to create, start and give us basic details on the website that we create.Website is going to be created by using %WEB_CREATE%.
ENDLOCAL
GOTO :EOF

No Comments