Update IIS Settings using Script

Posted by Techie Cocktail | 12:19 AM | , , | 0 comments »

Introduction
Internet Information Services (IIS) is a widely used Internet Services Platform for Microsoft Web Applications. The Web Applications are hosted on IIS by creating websites/virtual directories and/or application pools. Various settings need to be configured before and after the application is deployed on IIS. Some of the important settings are TCP Port, SSL Port, Connection Timeout, IIS log files properties, application pool settings and others.

Most of us configure these settings by going to the IIS Manager (start->Run->inetmgr) which everyone would be already aware of. But there is another approach to update the IIS Settings and that is using an IIS Admin script. The server administrators would know about its usage but for those who are not aware of this approache, you will believe that its quite easy to use it as well.

Lets see the script & related files locations and its usage. In this article, we would see how to read the existing websites, virtual directories (VDs) and app pools (APs) on IIS. Then we will see how to read the values of some their common configuration settings followed by updating the settings. We won't create or delete any websites, VD or APs.

Files and locations
The important files here are:
a. adsutil.vbs: This is THE script to GET or SET configuration settings in IIS.
Located at: C:\Inetpub\AdminScripts\

b. MetaBase.xml: This file stores the current IIS Settings in the XML Format.
Located at C:\%SystemRoot%\System32\Inetsrv\

c. MBSchema.xml: This file contains all the properties with their InternalName and datatypes. The internal names correspond to the property name that you would use to update the value using adsutil.vbs script.
Located at C:\%SystemRoot%\System32\Inetsrv\

These files should be secured and accessible only to administrators because of wrongly updated may break your web applications. But you need not exactly be worried because the backups of both of these XML Files are being maintained for us to rollback any changes which are located at C:\%SystemRoot%\System32\Inetsrv\History.

You can have a quick look at the Metabase files to get familiarized with the common property names and their datatypes that you require to update in IIS.

Let us now look at the usage of adsutil.vbs script and GET/SET some of the common properties.

Using the script
Commands to Analyze Websites, VDs & APs created on your IIS
a. The first thing is to list the instances of the websites, VDs and APs created on your iis. Using the instance name, you can target the settings that you need to read or update.

The below command enumerates the paths (instances) of all the websites, VDs, APs on your webserver. Using these paths, you can target the settings for the ones that you need to update.

c:\Inetpub\Adminscripts>adsutil.vbs enum /P /w3svc

The result will be something like this:

[/w3svc/1]
[/w3svc/1025764322]
[/w3svc/2]
[/w3svc/3]
[/w3svc/AppPools]

where [/w3svc/1], [/w3svc/2], [/w3svc/3] correspond to websites and results like [/w3svc/1025764322] are for VDs.

b. Get the details of a particular website.

c:\Inetpub\Adminscripts>adsutil.vbs enum /w3svc/1

Note: Do not include the /P (path) switch.

In the result, you will see the values of various configuration settings as in your IIS Manager for a website. The website name is determined by the 'ServerComment' property.

c. Get the details of a particular virtual directory.

c:\Inetpub\Adminscripts>adsutil.vbs enum /w3svc/1025764322

d. Read or update the details of specific property values.

Use GET to read and SET to update:

1. Get the ServerComment property value. This corresponds to your website name under Default Website.
c:\Inetpub\Adminscripts>adsutil.vbs GET /w3svc/1/ServerComment

2. Get the ServerBindings property value. This is corresponding to the TCP Port value in the website tab of your website.
c:\Inetpub\Adminscripts>adsutil.vbs GET /w3svc/1/ServerBindings

3. Get the SecureBindings property value. This is corresponding to the SSL Port value in the website tab of your website.
c:\Inetpub\Adminscripts>adsutil.vbs GET /w3svc/1/SecureBindings

4. Disable the Basic Authentication.
c:\Inetpub\Adminscripts>adsutil.vbs SET /w3svc/1/AuthBasic "False"

5. Set the ConnectionTimeout value to 120 seconds.
c:\Inetpub\Adminscripts>adsutil.vbs SET /w3svc/1/ConnectionTimeout 120

e. Get the list of App Pools.

c:\Inetpub\Adminscripts>adsutil.vbs enum /P /w3svc/AppPools

The above command gets the existing App Pools. To read or update the property value of an app pool, use GET or SET commands as shown in section d.

c:\Inetpub\Adminscripts>adsutil.vbs GET /w3svc/AppPools/<AppPoolName>/<InternalName>

The commands are easy to use and also you can get hold of the website, VDs or APs whose settings you need to update using the /P (path) in the command.

The only thing you need to know is the exact InternalName (PropertyName), that you can use in your commands. You can either refer to your Metabase xml file or for a quick check you can also use the below command and search through the appropriate name. Its result will have most of the common property names and their datatypes listed for you.

c:\Inetpub\Adminscripts>adsutil.vbs enum /w3svc

Isn't it easy and straightforward? Hope this makes your life easy and makes you happy too. Have fun!

References
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/d3df4bc9-0954-459a-b5e6-7a8bc462960c.mspx?mfr=true

0 comments