Using Windows Tools and Scripts to Manage IIS


You can use a variety of tools to manage your IIS 6.0 Web sites and permissions. Microsoft has provided many new tools for use at the command line and through scripting.

You can use IIS Manager to create, edit, or delete sites and properties. You can also use VBScript to perform those same tasks . If the task needs to be repeated several times, scripts are usually more efficient tools. If you want to see the status of the network or items such as disk space, the command line instruction might be faster.

Using the GUI to Manage IIS

For simple one-time management requirements the IIS Manager MMC console works fine. If you need to set up a new FTP site quickly, creating or editing a script might take too long. A simple rule to follow is: if you have to do it more than twice automate it.

Using Command-Line Administration

You often use the Windows command console to quickly find out status of a machine or the network. Examples of this are using ping to check the status of a network resource or running ipconfig to see what the IP addresses are associated with the network interfaces on the local machine.

Taking this logical approach one step further is the Windows Management Command Line (WMIC). This tool makes it easier for you to access WMI for quick tasks.

Managing IIS with ADSI Utilities

To see items such as which servers are bound to which TCP port number on the current server, they might run a command line request such as the adsutil .vbs example shown in Figure 19.6.

Figure 19.6. Show server bindings using ADSI utilities.

graphics/19fig06.gif

Using Windows Management Instrumentation (WMI)

In the past you could use WMI to passively monitor your network and servers. In the latest version of WMI you can also make changes to parameters of those networks and servers. There are two ways to use WMI to manage IIS. The first is via the Windows Scripting Host (WScript.exe) and the second with through the console, or command line with CScript.exe.

Windows Server 2003 has more than 6,000 managed resource properties that can monitored by WMI. Of these resources, more than 140 can be configured by WMI.

IIS 6.0 places some sample scripts in the Windows\System32 directory. These scripts are written in the Microsoft Visual Basic scripting language and use the IIS 6.0 WMI provider to access configuration information within the IIS metabase. The included scripts are as follows :

  • IISapp.vbs ” List process IDs and application pool IDs for currently running worker processes.

  • IISback.vbs ” Back up or restore IIS 6.0 configuration.

  • IISftp.vbs ” Create, delete, start, stop, and list FTP sites.

  • IISftpdr.vbs ” Create, delete, or display virtual directories under a given root.

  • IISconfg.vbs ” Export and import IIS 6.0 configuration to an XML file.

  • IISext.vbs ” Configure Web service extensions.

  • IISweb.vbs ” Create, delete, start, stop, and list Web sites.

  • IISvdir.vbs ” Create and delete virtual directories, or display the virtual directories of a given root.

Console-based Scripts Run with the CScript Engine

Console-based scripts run with the CScript engine. To force the WScript.Echo lines to display in the Command Prompt window call your script preceding it with CScript //nologo.


Monitoring Hard Disk Space

One of the important duties of an IIS administrator is making sure that the drives don't fill up and crash the server. The following is a sample script to monitor hard disk utilization:

 
 Const LOCAL_HARD_DISK = 3 strComputer = " servername " Set objWMIService = GetObject(" winmgmts :"_ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colMonitoredDisks = objWMIService.ExecNotificationQuery _ ("Select * from __instancemodificationevent within 30 where " _ & "TargetInstance isa 'Win32_LogicalDisk'") i = 0 Do While i = 0 Set objDiskChange = colMonitoredDisks.NextEvent If objDiskChange.TargetInstance.DriveType = LOCAL_HARD_DISK Then If objDiskChange.TargetInstance.Size < 10000000000 Then Wscript.Echo "Hard disk space is below 10000000000 bytes." End If End If Loop 

If the hard disk on the local machine drops below 10GB free then a dialog box pops up on the screen and says Hard disk space is below 10000000000 bytes . This is just a simple example using Windows Scripting and WMI to monitor computers on the network.

Obviously an IIS administrator wouldn't be standing at the console of the IIS server waiting to see if the hard disk space is running out. A more realistic scenario would be to have the preceding script monitoring the group of computers running IIS and FTP send an e-mail if the drive space dropped below a certain number of bytes free.

Querying Log Files for Stop Errors

You need to know pertinent information when monitoring the health of your servers. Poring over hundreds or thousands of entries to find meaningful errors can be tedious . The following is a sample script to query the System event log on the local machine for stop errors that have the string SaveDump in them:

 
 strComputer = "servername" Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colLoggedEvents = objWMIService.ExecQuery _ ("Select * from Win32_NTLogEvent Where Logfile = 'System'" _ & " and SourceName = 'SaveDump'") For Each objEvent in colLoggedEvents Wscript.Echo "Event date: " & objEvent.TimeGenerated Wscript.Echo "Description: " & objEvent.Message Next 

This script is an example of how you might parse through very large log files and only extract the data that helps them troubleshoot hard errors on their servers.



Microsoft Windows Server 2003 Insider Solutions
Microsoft Windows Server 2003 Insider Solutions
ISBN: 0672326094
EAN: 2147483647
Year: 2003
Pages: 325

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