IIS 6 Administration

Let’s move on now and look at managing IIS using the command-line WMI scripts included in the \System32 directory of your IIS machine. We’ll start by looking at the iisweb.vbs script, which you can use to create, delete, start, stop, pause, and query websites from the command line, either while logged on interactively to the local IIS machine or from a remote machine as discussed in the section “Running Scripts” earlier in this chapter. I’ll break these tasks down into several groups and walk you through them using command-line sessions.

For the purpose of the walkthroughs in this section and those following, first make sure your IIS machine has five IP addresses assigned to the local area connection. In the following examples these addresses are 172.16.11.215 through 172.16.11.219, but if you have different addresses assigned you can easily modify the procedures. Make sure also that:

Finally, leave IIS Manager open so you can refresh it by pressing F5 to verify the results after you run each of the following admin script examples. If F5 doesn’t refresh IIS Manager, try closing and reopening the console.

Note 

All the WMI admin scripts included with IIS 6 require Administrator credentials for running them and only work on machines running version 6 of IIS.

Creating Websites

Creating a website using iisweb.vbs is simple. Let’s say you want to create a new website called Accounting that has an IP address of 172.16.11.216 and C:\finance as its home directory, but that this directory does not yet exist on the server. Here’s a command- line session showing how to do this from a command-prompt window opened on the IIS machine (you’re either logged on interactively to the IIS machine or connected to it using Remote Desktop or Telnet):

C:\>iisweb /create C:\finance Accounting /i 172.16.11.216 Connecting to server ...Done. Server        = SSRV215 Site Name     = Accounting Metabase Path = W3SVC/376238833 IP            = 172.16.11.216 Host          = NOT SPECIFIED Port          = 80 Root          = C:\finance Status        = STARTED

Let’s analyze this, first by looking at the syntax of the command, which is something like this:

iisweb /create Path SiteName /i IPAddress

Taking this apart, you see that:

Looking at the output of the iisweb /create command in the preceding session, note that your new site is

Now let’s create another site on the machine, this time making the home directory C:\HR, the site name Human Resources, and the IP address 172.16.11.217. Because the HR department wants to keep this site under wraps, you’ll assign it a nonstandard port number such as 8050 (anything above 1023 will do so that it will not conflict with well-known port assignments). You’ll also assign the site a host header of hr.mtit.com. And because the site has no content in it yet, you need to make sure the new site is stopped and not started after it is created. Finally, instead of running iisweb on the machine itself, run it from another Windows Server 2003 machine on the network. Let’s say the machine you’re running it on is part of the mtit.com domain, but the IIS machine is a stand-alone machine on the DMZ of your network. You’ll need the right credentials to create the site on your IIS machine, so use the local Administrator account on that machine (or SSRV215\Administrator because the name of the machine is SSRV215) and also the password. Here’s the syntax to accomplish all this and the results that are displayed when the script runs:

C:\>iisweb /create C:\HR "Human Resources" /b 8050 /i 172.16.11.217 /d hr.mtit.com /dontstart /s 172.16.11.215 /u SSRV215\Administrator /p pa$$w0rd Connecting to server ...Done. Server        = 172.16.11.215 Site Name     = Human Resources Metabase Path = W3SVC/1525757177 IP            = 172.16.11.217 Host          = hr.mtit.com Port          = 8050 Root          = C:\HR Status        = STOPPED

Here are the new elements of the syntax of iisweb that are being used in this command:

The output of the script suggests it ran successfully, but, to make sure, open the properties sheet for the site in IIS Manager and make sure the settings are as expected; then trying starting the site and see if it works. If you can’t start the site, something was wrong with your script that resulted in a faulty configuration for the site—try deleting it and creating it again.

By the way, now that you know how to use this script to connect to a remote IIS machine and run it on that machine, I’ll keep things simple for the remaining examples by running them locally on the IIS machine. Once you understand the /s and /u and /p switches and how they work, you’ll see how any of these scripts can be run remotely.

A few more things to note when creating websites using this script:

Starting, Stopping, and Pausing Websites

You can also use iisweb to start, stop, and pause websites on your machine. Pausing a site prevents new client connections from being formed but doesn’t break off existing connections the way stopping does. Here’s how to stop and then start the Accounting website created earlier:

C:\>iisweb /stop Accounting Connecting to server ...Done. Server W3SVC/376238833 has been STOPPED C:\>iisweb /start W3SVC/376238833 Connecting to server ...Done. Server W3SVC/376238833 has been STARTED

Notice that you can use either the friendly name or metabase ID of the site you want to stop or start.

Now try pausing both the Accounting and Human Resources websites and then continue (unpause) them by starting them again:

C:\>iisweb /pause Accounting "Human Resources" Connecting to server ...Done. Server W3SVC/376238833 has been PAUSED Server W3SVC/1525757177 has been PAUSED C:\>iisweb /start accounting "human resources" Connecting to server ...Done. Server W3SVC/376238833 has been CONTINUED Server W3SVC/1525757177 has been CONTINUED

Note from this example that:

You might think that iisweb /pause would pause all websites on the machine, but unfortunately this is not the case. However, as you saw earlier, you can always stop all websites by using iisreset /stop to stop the WWW service.

Querying Websites

To display all the websites on our IIS machine:

C:\>iisweb /query Connecting to server ...Done. Site Name (Metabase Path)                     Status  IP              Port  Host ============================================================================== Default Web Site (W3SVC/1)                    STARTED ALL             80    N/A Accounting (W3SVC/376238833)                  STARTED 172.16.11.216   80    N/A Human Resources (W3SVC/1525757177)            STARTED 172.16.11.217   8050  hr.mtit.com

Note that the name, metabase ID, status, IP address, port, and host header name(s) are displayed for all sites on your server. You could also query for information about one or more sites instead of all of them:

C:\>iisweb /query "Default Web Site" w3svc/1525757177 Connecting to server ...Done. Site Name (Metabase Path)                     Status  IP              Port  Host ============================================================================== Default Web Site (W3SVC/1)                    STARTED ALL             80    N/A Human Resources (W3SVC/1525757177)            STARTED 172.16.11.217   8050  hr.mtit.com

Deleting Websites

Finally, delete your Human Resources website since you don’t need it anymore:

C:\>iisweb /delete "Human Resources" Connecting to server ...Done. Server W3SVC/1525757177 has been deleted

Use IIS Manager to verify that the site is gone, or use iisweb /query to list the remaining sites. You can delete multiple websites at the same time by naming them in succession.

Note 

Deleting a website does not delete its associated home directory.

Категории