Do complex IIS management tasks easily with AppCmd command piping

As much as I hate to re-post someone else's content, I've been real busy in the past few weeks and havent had a chance to post new stuff - and today I saw Kanwal's post on a very near and dear subject of mine: AppCmd command pipelining.

Things you can do by piping appcmd commands

The post covers command pipelining, the advanced AppCmd feature that enables complicated management tasks to be expressed simply by combining multiple related appcmd commands, that operate on a pipeline of results generated by prevous commands.

For example:

AppCmd list apppools /state:Stopped finds the application pools that are stopped.

AppCmd start apppool XYZ starts the specified apppool.

What if you wanted to find the stopped apppools, and start them?  You could write a script, with a FOR loop, etc - or you can use AppCmd piping to do it like a pro:

AppCmd list apppools /state:Stopped /XML | AppCmd stop apppools /in

The /XML switch in the first command outputs the result of the first command in XML, and the /IN switch of the second command allows the list of apppools to stop to come in from STDIN.

This can be applied as many times as you want with most AppCmd commands.  Since appcmd allows you to query for objects with any of its properties, you can turn it the command piping ability into a very powerful way to do complex tasks - for example:

appcmd list sites /state:started /traceFailedRequestsLogging.enabled:true /XML |
     appcmd list apps /IN /XML |
        appcmd list apppools /IN /XML | 
            appcmd recycle apppools /IN

This finds all sites that are started and have Failed Request Tracing enabled, finds their applications, then finds the apppools to which they belong, and recycles them.

Before you ask - I designed and implemented this feature before I was exposed to Powershell, and was happy to see that Powershell supports this generically for most of its commands.  If I had known that ahead of time, I may have never implemented the support in AppCmd ... but as history would have it, I did, and now you get to take advantage of this capability in IIS7, without Powershell installed or the requirement to write your own powershell commandlets.

Read Kanwal's article for more examples of commands - I'll be sure to post my favorite ones, and some cool tricks using pipelining, in the near future.

Published 19 June 07 12:22 by Mike Volodarsky
Filed under: , ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Mike Volodarsky's WebLog said on June 19, 2007 1:04 PM:

As much as I hate to re-post someone else's content, I've been real busy in the past few weeks and havent

# Mike Volodarsky's ServerSide said on October 6, 2007 2:05 AM:

IIS7 provides quite a few ways to create websites, applications, and application pools. The simplest

# ASP.NET Debugging said on April 1, 2008 9:38 AM:

So with IIS7, there is a new way to get data out about your web server, using the new appcmd.exe process.

# Bernard Vander Beken said on February 19, 2009 5:34 AM:

Nice article!

I am aware of how the powershell IIS provider can be used to create websites.

Do you know of a similar mechanism for the powershell approach?

- exporting XML configuration of a website definition.

- importing XML configuration of a website definition.

# Rekha said on October 28, 2010 2:57 AM:
how do we use AppCMD in 64Bit envts?
# Aaron Neff said on March 14, 2011 1:32 AM:
Hi Mike, Thank you very much for creating the appcmd tool! It should be quite helpful. I seem to be having trouble adding a virtual directory to each IIS site. I thought this should work: appcmd list site -xml | appcmd add vdir -in /path:/mydir /physicalpath:c:\mydir I thought SITE.NAME, from "list site", would automatically be used as the required app.name, in "add vdir". It is not. Was the task of 'adding a virtual directory to each site' considered, in the creation of the appcmd tool? If so, could you please share with me how to do this? If not, could it please be considered for the next version of appcmd? I understand you're no longer with Microsoft, but hopefully someone is still maintaining this helpful tool. I've also posted this question to forums.iis.net: http://forums.iis.net/p/1176391/1974795.aspx#1974795 I've also asked Kanwal the same question at: http://blogs.iis.net/ksingla/archive/2007/06/17/things-you-can-do-by-piping-appcmd-commands.aspx Thanks very much, in advance for your time!, -Aaron
# said on April 29, 2011 4:45 AM:

Chaussures Nike Sale: http://www.maxpascher.com

# Aaron Neff said on October 8, 2011 12:33 PM:
Hi Mike, Does 'set config' support the '/in' switch? As in this example: C:\Windows\system32\inetsrv\appcmd.exe list site /xml | C:\Windows\system32\inetsrv\appcmd.exe set config /in /section:isapiFilters /+"[name='MyFilter',path='C:\my_filter.dll']" I've also asked this question in the IIS.net forums: http://forums.iis.net/p/1182209/1998492.aspx#1998492 Thanks!, -Aaron

Leave a Comment

(required) 
(optional)
(required) 
Enter the code you see below


About Mike Volodarsky

For the past 5 years, I was the core Program Manager for Microsoft ASP.NET 2.0 and IIS 7.0 products. I drove the design and development of the IIS 7.0 web server core, the IIS FastCGI support, the AppCmd command line tool, the ASP.NET Integrated pipeline, and other special projects around server security, performance, and scalability. Now, I am working on my own on cutting edge web server tech on top of the Microsoft IIS platform, and continue blogging about it here.

About me



Until 2008, I was the core server Program Manager for the IIS 7.0 and ASP.NET 2.0 products at Microsoft.


View Michael Volodarsky's profile on LinkedIn


This is my company. We build expert performance and scalability tech for web applications on the Windows Server stack.
LeanServer Sentinel: Explore and instantly diagnose your production ASP.NET applications Sentinel beta starts on August 3rd! Register now!


Writings



TechNet Magazine
>Top 10 Performance Improvements in IIS 7.0

MSDN Magazine
>IIS 7.0: Build Web Server Solutions with End-To-End Extensibility
>IIS 7.0: Enhance Your Apps with the Integrated ASP.NET Pipeline
>IIS 7.0: Explore The Web Server For Windows Vista And Beyond
>Design and Deploy Secure Web Apps with ASP.NET 2.0 and IIS 6.0
>Fast, Scalable, and Secure Session State Management for Your Web Applications


Tools and Modules

LeechGuard
IconHandler 2.0
DirectoryListing
HttpRedirection
IIS Auth for Wordpress
iisschema.exe
PortCheck.exe v2.0

Popular Posts

- ASP.NET 2.0 Breaking Changes on IIS 7.0
- Develop IIS7 modules and handlers with .NET
- Troubleshoot IIS7 errors like a pro
- Troubleshooting 503 / "service unavailable" errors
- Troubleshooting "server not found" errors
- Create IIS7 sites, applications, and virtual directories
- Run Ruby on Rails with IIS FastCGI
- VS Debugging of ASP.NET applications on Windows Vista
- Stop hot-linking with IIS and ASP.NET

Tags

Search

Go

This Blog

Archives

Good IIS Blogs

Disclaimer

These postings are provided as is with no warranties, and confer no rights. The views expressed in this blog are entirely my own.

Syndication