Managing Websites

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:

  • Your IIS machine is running in worker process isolation mode.

  • The only website present is the Default Web Site.

  • The FTP service is installed and the only FTP site present is the Default FTP Site.

  • The only application pool present is the DefaultAppPool, and the only application this contains is the Default Application.

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:

  • Path is the physical location of the home directory for the new site. Note that if this directory doesn’t exist on the IIS machine, the script creates it.

  • SiteName is the friendly or descriptive name of the new site for display in IIS Manager. If your site name has spaces in it, enclose the site name in quotation marks.

  • The /i switch must be followed by the IP address you want to assign to the site. If you omit this switch, IIS will make All Unassigned the IP address for the new site, and this will conflict with the settings of the existing Default Web Site and the new site will not be able to start.

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

  • Located on an IIS machine named SSRV215

  • Has the friendly name Accounting, as expected

  • Has the metabase path W3SVC/376238833, which indicates that it is a website (the W3SVC part) with an internal ID number 376238833 (see Figure 11-13)

    click to expand
    Figure 11-13: Accounting website created using iisweb.vbs

  • Has IP address 172.16.11.216, as expected

  • Has no host header name assigned to it

  • Listens on port 80, the standard HTTP port number

  • Has C:\finance as its home (root) directory, as expected

  • Is started and running on the IIS machine

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 /b 8050 option causes the new site to listen on port 8050.

  • The /d hr.mtit.com option assigns the host header name hr.mtit.com to the new site.

  • The /dontstart switch specifies that the site should not be started after it is created.

  • The /s 172.16.11.215 option indicates that the script should be run on the remote IIS machine having this IP address (or you could use SSRV215 for its name here instead, or its DNS name if DNS is being used).

  • The /u SSRV215\Administrator option indicates that you want to run the script using the credentials of the local Administrator account on the stand-alone IIS machine named SSRV215. If the IIS machine belonged to a domain like mtit.com, you would use /u MTIT\Administrator here instead.

  • The /p pa$$w0rd option is used to specify the password of the Administrator credentials being used to perform the command. The Administrator account used must be the local Administrator account on the remote IIS machine (if it belongs to a workgroup) or a domain Administrator account (if it belongs to a domain). You could also use an account that has been delegated the appropriate authority.

    Caution 

    These scripts send Administrator credentials unencrypted over the network, so only use them to manage IIS machines located on your LAN. Do not use them for managing IIS machines over the Internet unless you are running them using Remote Desktop, which encrypts all communications.

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:

  • Path must always precede SiteName in the command’s syntax.

  • The home directory for the new site must be local to the IIS machine. You can’t specify a network share using a UNC path when you use this script. If you need to give your new site a remote home directory, you must change the location afterward with IIS Manager.

  • It’s possible for two websites to have the same friendly name in IIS Manager, so in theory you could use the script to create another site called Default Web Site if you like. But internally (in the metabase), the two sites are described using their unique site IDs so IIS won’t get confused about which is which.

  • All other properties of your newly created site are inherited from the properties of the Web Sites node above it (see the console tree in IIS Manager). You can customize your new site by modifying its properties afterward using IIS Manager.

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 can specify multiple names of sites for starting, stopping, or pausing them.

  • The names of sites are not case specific (accounting is the same as Accounting).

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.




IIS 6 Administration
IIS 6 Administration
ISBN: 0072194855
EAN: 2147483647
Year: 2003
Pages: 131
Authors: Mitch Tulloch

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net