New features in configuration system and appcmd in IIS 7.5

Following new features have been added to IIS configuration system and appcmd command line tool in IIS 7.5.

Configuration System

1.       Configuration system tracing and logging
In IIS 7.5, IIS native configuration system can generate trace events capturing all IIS configuration activity. Because all IIS administrative tools (WMI, appcmd, MWA, UI, Powershell etc) call into native configuration system, events are generated irrespective of which administrative tool is used to read/write IIS configuration. Tracing is not enabled by default. You can go to “Application and Service Logs->Microsoft->Windows->IIS-Configuration” in event viewer and enable tracing. IIS generates 4 kinds of events. These are administrative, operational, analytic and debug. Right click on areas in event viewer and select “enable log” for categories you want to enable tracing.

2.       Ability to work with multiple .Net versions
IIS configuration system has the ability to work with multiple .net versions. For this configuration system honors metadata defaultManagedRuntimeVersion. If set, IIS will use this information to find which machine.config and root web.config it should work against. Default version assumed is v2.0. If you want to make configuration system go against other .net version, you are required to set defaultManagedRuntimeVersion metadata. If the configuration path identifies an application, configuration system automatically figures out the version by checking managedRuntimeVersion set for the application pool for the application. All administrative tools are updated to allow working with different versions of NetFx.

3.       Shared configuration now can be configured to use polling instead of change notifications to track changes to applicationHost.config file. This can be configured by specifying “enableUncPolling” and “pollingPeriod” properties in configurationRedirection section. Default value of enableUncPolling is false which means the feature is not turned on by default.

4.        “availableReadableMetadata” and “availableWritableMetadata” metadata properties are available in IAppHostAdminManager, IAppHostElement, IAppHostMethod, IAppHostProperty interfaces. These can be used to find what readable and writable metadata is available for each object.

Appcmd

1. Appcmd now has ability to add <clear/> tag in the collections using ‘~’. Command to clear <error> collection entries in httpErrors section will be following.
appcmd set config /section:httpErrors /~

2. Previously appcmd could only add one type of addElement collection type which limited its utility for authorization section as the addElement could be allow or deny. Now appcmd can be used to add element of a paricular type. Command to add deny entry in authorization section will be as following.
appcmd set config /section:authorization /+deny[verbs=’put’]
appcmd set config /section:authorization /-deny[verbs=’get’]

3. /clr switch can be used to specify which version of .net framework you want to work against when dealing with machine.config and web.config. If this switch is not specified, version dotnet version 2.0 will be assumed.appcmd list config /section:profile /clr:4 (or v4 or 4.0).

4. /admin switch can be used to map configuration path MACHINE/WEBROOT to administration.config. This enables appcmd to be used against administration.config. So command to read moduleProviders section from administration.config will be “appcmd list config /section:moduleProviders /admin”

Hope this helps.
Kanwal

Things you can do by piping appcmd commands

Here are some of the cool things you can do by piping appcmd commands together in IIS7.

Application Pools

1. Recycle all application pools (replace recycle with start/stop to start/stop all apppools)
appcmd list apppool /xml | appcmd recycle apppool /in

2. Stop application pools with word "cheap" in it
appcmd list apppool /name:"$=*cheap*" /xml | appcmd stop apppool /in


3. Set property enable32BitAppOnWin64 to true for all apppools (Filter apppools as in 2 if needed)
appcmd list apppool /xml | appcmd set apppool /in /enable32BitAppOnWin64:true

4. Start apppools which are stopped
appcmd list apppool /state:Stopped /xml | appcmd start apppool /in

5. Recycle application pools which are used in some applications
appcmd list app /xml | appcmd list apppool /in /xml | appcmd recycle apppool /in
appcmd list app /xml | appcmd recycle apppool /in (This might recycle one apppool multiple times)

6. Recycle apppools serving website “Default Web Site”
appcmd list site "Default Web Site" /xml | appcmd list app /in /xml | appcmd list apppool /in /xml | appcmd recycle apppool /in
appcmd list app /site.name:"Default Web Site" /xml | appcmd list apppool /in /xml | appcmd recycle apppool /in

Sites

7. Start all the sites (Replace start with stop to stop all sites)
appcmd list site /xml | appcmd start site /in

8. Start the sites which are stopped
appcmd list site /state:stopped /xml | appcmd start site /in

9. Set serverAutoStart to false for all sites
appcmd list site /xml | appcmd set site /serverAutoStart:false /in

10. Keep sites config data and restore later
appcmd list site /config /xml > sites.xml
appcmd add sites /in < sites.xml

Applications and Vdirs

11. Delete all apps which are using a particular apppool
appcmd list apppool DefaultAppPool /xml | appcmd list app /in /xml | appcmd delete app /in

12. Move all applications in a site to NewAppPool apppool
appcmd list app /site.name:"Default Web Site" /xml | appcmd set app /in /applicationPool:NewAppPool

13. List all sites with "/test" app
appcmd list app /path:"/test" /xml | appcmd list site /in

14. List apps created by user10 (assuming all his apps under a folder whose name contains user10)
appcmd list vdir /physicalPath:"$=*user10*" /xml | appcmd list app /in

15. List sites which read from C:\inetput\wwwroot
appcmd list vdir /physicalPath:C:\inetput\wwwroot /xml | appcmd list app /xml /in | appcmd list site /in

16. List the vdirs of sites which are stopped
appcmd list site /state:stopped /xml | appcmd list app /xml /in | appcmd list vdir /in

Worker processes and Requests

17. Stop apppools of requests running for more than 60 seconds
appcmd list request /xml /time:"$>60000" | appcmd list apppool /in /xml | appcmd stop apppool /in

18. List apps served by wp 3600
appcmd list wp 3600 /xml | appcmd list apppool /xml /in | appcmd list app /in

Modules

19. Disable all managed modules
appcmd list module /preCondition:managedHandler /xml | appcmd delete module /in

20. Uninstall all native modules
appcmd list module /type:"" /xml | appcmd uninstall module /in

21. Unlock all module entries under system.webServer/modules (won’t work on vista)
appcmd list module /xml | appcmd set config /lockItem:false /in

Configuration

22. Keep config of a particular section and restore later
appcmd list config http://localhost/app1/ /section:caching /xml /config > config.xml
appcmd set config
http://localhost/app1 /in < config.xml

Backups and Traces

23. Delete all backups
appcmd list backup /xml | appcmd delete backup /in

24. List sites generating 404
appcmd list trace /statusCode:404 /xml | appcmd list site /in

 

Hope this helps.

-Kanwal

Steps to enable tracing using appcmd

Here are the steps you need to enable tracing for a site using appcmd.

 

 

1.       Enable tracing for site.
2.       Enable tracing for all request paths and for all response codes.
3.       Appcmd leaves verbosity to default value “warning”. Get the providers count to change verbosity in step 4.
4.
       Change verbosity to verbose for all providers.

 

@REM Step1
@REM Change site name in the commands if you need to

 

 

%windir%\System32\inetsrv\appcmd configure trace "Default Web Site" /enablesite

 

 

@REM Step2
@REM Change /statusCodes if you don’t want to enable tracing for all response codes.
@REM Status code range doesn’t work in vista client. Change accordingly.
@REM Use /path to enable tracing for requests to particular file. Eg. /path:*.aspx
@REM Use /timeTaken to enable tracing based on time taken to process request

 

 

%windir%\System32\inetsrv\appcmd configure trace "Default Web Site" /enable /statusCodes:100-999 -commit:apphost

 

 

@REM Step 3
@REM Change %%V to %V if you are not running in batch mode

 

%windir%\System32\inetsrv\appcmd list config "Default Web Site" -section:traceFailedRequests -text:* | findstr provider:> traceproviders.txt
SET PROCOUNT=-1
for /F %%V in (traceproviders.txt) do set /a PROCOUNT = PROCOUNT + 1

 

@REM Step 4
@REM Change %%V to %V if you are not running in batch mode

for /L %%V in (0,1,%PROCOUNT%) do %windir%\System32\inetsrv\appcmd set config "Default Web Site" /section:traceFailedRequests /[path='*'].traceAreas.[@%%V].verbosity:Verbose -commit:apphost

 

 

 

You can remove step3 and change step 4 to run blindly from 0 to 3. You might get invalid index errors from appcmd if you have less than 4 providers installed on your machine which you can ignore.

 

 

-Kanwal-

AppcmdUI – appcmd command autocompletion tool

Do you always find yourself using “/?” in appcmd to find what switches you need? Do you always run “appcmd list” commands to see the list of apppools/sites/apps/traces etc before actually running the command? Do you always end up opening schema when working with "appcmd config" commands? Worry no more. I have written AppcmdUI to alleviate your pains. AppcmdUI provides you available options at each step so that you only need to pick the option from the list as in the snapshot below.

AppcmdUI

 

 

 

 

 

Features
§  Works with both “appcmd <object> <verb>” and “appcmd <verb> <object>” command styles.
§  Shows list of objects and verbs available. Builds auto complete list dynamically so that you see only few options.
§  Builds list of current application pools, sites, applications, virtual directories, backups, module, traces, worker processes and shows them as parameter values. Updates this list when “appcmd add/delete” commands are used.
§  Force update option for tool to pick latest configuration data when “appcmd set config” or other scripts/tools are used to add/delete apppools/sites/apps/vdirs.
§  Parses the schema and shows section names in commands which require section names. Custom defined sections are automatically picked.
§  When working with a particular section, shows list of attributes/elements/collections and helps you setting attributes and adding/removing collection elements.
§  Shows attributes, elements, collections which you can set using “appcmd set apppool|site|app|vdir|module” commands.
§  Shows general appcmd parameters. Uses –parameter for general parameters rather than /parameter to show they are different.
§  Shows possible attributes when “appcmd –text:” used.
§  Can execute command and see the output in the same window.
§  Shows examples of commands you are working with which are in “appcmd <verb> <object> /?” help.
§  Supports auto complete and command execution even when piping commands together.
§  Limited support for identifiers. There is a corresponding /parameter option for most of the identifiers. Uses /parameter:value.
§  NEW – Up-down lets you browse recently executed commands.
§  NEW – If you run the application without sufficient privileges, it shows UAC dialog box for you to grant access.

Installation
You can use AppcmdUI only on machines which has IIS7 and appcmd.exe installed. Download attached AppcmdUIInstall.zip and run self extracting package AppcmdUIInstall.exe. Extract files (AppcmdUI.exe and AppcmdUI.xml) to a folder on your machine and you are done.

How to Use
Run AppcmdUI.exe as elevated (newest version will demand administrator access if needed only if when you don't run it from command window). Running from an elevated command prompt is not enough because of UAC settings for applications which are not under windows directory. Start typing appcmd commands in the textbox. You will get list of available options as you go along. Use mouse or down/up arrow keys to select any of available options. Auto complete list is updated every time you type space/comma/colon/dot so that you only see few options which are valid in current context and helps you choose only next option. Snapshot below shows list of available objects in appcmd which are shown on typing “appcmd “.

Appcmd Objects

 

 

AppcmdUI uses “appcmd <object> <verb>” format. So you see list of available objects after appcmd. If you type “appcmd <verb>” and then space, you will see list of objects which you can use with the verb you typed. If you want to get list of verbs and not objects when you type “appcmd “, you can set <verb> <object> option in the menu as shown below.

 

 

 

Change command style


When you have the <verb> <object> option set, you will see the available verbs after appcmd as shown below.

 

Appcmd Verbs


Once you have selected verb and object, you will see list of available options which can be used with them.

Parameter Values


When you need the available application pools, sites, applications, virtual directories, backups, traces, worker processes in the command, AppcmdUI shows the values you can use. Next time when you need to start or stop apppools/sites, delete apps/vdirs or inspect traces, you won’t need “appcmd list” command first.

Parameter Values

 

 

Force Update
AppcmdUI picks up list of application pools, sites, applications, virtual directories, backups once and update this list only when “appcmd add/delete” calls are made. If you use “appcmd set config” call or some other means of creating apppools/sites/apps etc, you would see the list is not updated. Eg. If a new application pool “AppcmdAppPool” is created using “appcmd set config /section:applicationPools /+[name='AppcmdAppPool']", that apppool is not shown in the list of available apppools.

 

 

Using Appcmd set

 

 

You can use "Force Update" option to force AppcmdUI to update list of application pools, sites, applications etc.

 

 

Force Update

 

 

After forcing an update, "AppcmdAppPool" is shown in the list of available application pools.

 

 

After force update

 

 

Working with configuration
When you are working with “appcmd list config” or “appcmd set config”, you get list of available sections as soon as you enter “/section:” as shown below.

 

 

Available sections

 

 

AppcmdUI also shows you list of attributes, elements, collections when working with set/list commands. Adding a collection element is now a whole lot easier as you can see below.

 

 

Add Collection Element

 

 

List of attributes, elements, collections is also available when you work with “appcmd set <apppool|site|app|vdir”. In the snapshot below, I am getting attributes which can be set for a virtual directory.

 

 

 

vdir attributes

Schema elements are available with various list commands as well after you type “-text:”. –text with list command allows you to print only particular attributes.

List properties

 

 

Hope you find working with appcmd much easier with this.

 

 

 

 

 

 

-Kanwal